Skip to content

Commit e584cb1

Browse files
authored
Fix divide by 0 in shadow utils for some scenes #2209 (#2210)
1 parent 965a813 commit e584cb1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,10 @@ public static void updateShadowCamera(ViewPort viewPort,
569569
float scaleX, scaleY, scaleZ;
570570
float offsetX, offsetY, offsetZ;
571571

572-
scaleX = (2.0f) / (cropMax.x - cropMin.x);
573-
scaleY = (2.0f) / (cropMax.y - cropMin.y);
572+
float deltaCropX = cropMax.x - cropMin.x;
573+
float deltaCropY = cropMax.y - cropMin.y;
574+
scaleX = deltaCropX == 0 ? 0 : 2.0f / deltaCropX;
575+
scaleY = deltaCropY == 0 ? 0 : 2.0f / deltaCropY;
574576

575577
//Shadow map stabilization approximation from shaderX 7
576578
//from Practical Cascaded Shadow maps adapted to PSSM
@@ -595,7 +597,8 @@ public static void updateShadowCamera(ViewPort viewPort,
595597
offsetY = FastMath.ceil(offsetY * halfTextureSize) / halfTextureSize;
596598
}
597599

598-
scaleZ = 1.0f / (cropMax.z - cropMin.z);
600+
float deltaCropZ = cropMax.z - cropMin.z;
601+
scaleZ = deltaCropZ == 0 ? 0 : 1.0f / deltaCropZ;
599602
offsetZ = -cropMin.z * scaleZ;
600603

601604

0 commit comments

Comments
 (0)