From e584cb194c5862e5805ce318761691c7181e96a2 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Sat, 2 Mar 2024 10:32:32 +0100 Subject: [PATCH] Fix divide by 0 in shadow utils for some scenes #2209 (#2210) --- jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java b/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java index edb78a38bf..388310a920 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java +++ b/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java @@ -569,8 +569,10 @@ public static void updateShadowCamera(ViewPort viewPort, float scaleX, scaleY, scaleZ; float offsetX, offsetY, offsetZ; - scaleX = (2.0f) / (cropMax.x - cropMin.x); - scaleY = (2.0f) / (cropMax.y - cropMin.y); + float deltaCropX = cropMax.x - cropMin.x; + float deltaCropY = cropMax.y - cropMin.y; + scaleX = deltaCropX == 0 ? 0 : 2.0f / deltaCropX; + scaleY = deltaCropY == 0 ? 0 : 2.0f / deltaCropY; //Shadow map stabilization approximation from shaderX 7 //from Practical Cascaded Shadow maps adapted to PSSM @@ -595,7 +597,8 @@ public static void updateShadowCamera(ViewPort viewPort, offsetY = FastMath.ceil(offsetY * halfTextureSize) / halfTextureSize; } - scaleZ = 1.0f / (cropMax.z - cropMin.z); + float deltaCropZ = cropMax.z - cropMin.z; + scaleZ = deltaCropZ == 0 ? 0 : 1.0f / deltaCropZ; offsetZ = -cropMin.z * scaleZ;