From 946b3ea6c08be39b059354d28037514628c62fc7 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Fri, 7 Mar 2025 17:06:02 -0500 Subject: [PATCH 1/3] Fix exception when using Instancing with Fog in PBR The fog code in PBRLighting.j3md is encountering the same issue that was reported before with Lighting.j3md : https://github.com/jMonkeyEngine/jmonkeyengine/pull/1458 This PR should fix the issue. --- .../src/main/resources/Common/MatDefs/Light/PBRLighting.vert | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert index 23427c0795..eb6cdd303c 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert @@ -88,7 +88,7 @@ void main(){ #endif #ifdef USE_FOG - fogDistance = distance(g_CameraPosition, (g_WorldMatrix * modelSpacePos).xyz); + fogDistance = distance(g_CameraPosition, (TransformWorld(modelSpacePos)).xyz); #endif } From c372b325783ea6fe69dbce9c394265b003d5172c Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Fri, 7 Mar 2025 19:09:05 -0500 Subject: [PATCH 2/3] Minor formatting update to Lighting.vert --- .../src/main/resources/Common/MatDefs/Light/Lighting.vert | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert index d4242ee8ad..7b68941719 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert @@ -186,6 +186,6 @@ void main(){ #endif #ifdef USE_FOG - fog_distance = distance(g_CameraPosition, (TransformWorld(modelSpacePos)).xyz); + fog_distance = distance(g_CameraPosition, (TransformWorld(modelSpacePos)).xyz); #endif -} \ No newline at end of file +} From 94cba8916d0ddb00f0ef13f0150ffd396e5ed8f6 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Fri, 7 Mar 2025 19:22:24 -0500 Subject: [PATCH 3/3] rename varying fog_distance to fogDistance to match expected name in MaterialFog.glsllib --- .../src/main/resources/Common/MatDefs/Light/Lighting.vert | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert index 7b68941719..c1460cc9be 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert @@ -10,8 +10,8 @@ // fog - jayfella #ifdef USE_FOG -varying float fog_distance; -uniform vec3 g_CameraPosition; + varying float fogDistance; + uniform vec3 g_CameraPosition; #endif uniform vec4 m_Ambient; @@ -186,6 +186,6 @@ void main(){ #endif #ifdef USE_FOG - fog_distance = distance(g_CameraPosition, (TransformWorld(modelSpacePos)).xyz); + fogDistance = distance(g_CameraPosition, (TransformWorld(modelSpacePos)).xyz); #endif }