Skip to content

Commit

Permalink
Fix divide by 0 in shadow utils for some scenes #2209 (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Mar 2, 2024
1 parent 965a813 commit e584cb1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;


Expand Down

0 comments on commit e584cb1

Please sign in to comment.