diff --git a/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java index 0b50f8be4b..38c7a808ff 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java +++ b/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2025 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -69,7 +69,8 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer { protected float[] splitsArray; protected DirectionalLight light; protected Vector3f[] points = new Vector3f[8]; - //Holding the info for fading shadows in the far distance + protected final Vector3f tempVec = new Vector3f(); + private boolean stabilize = true; /** @@ -97,10 +98,12 @@ public DirectionalLightShadowRenderer(AssetManager assetManager, int shadowMapSi } private void init(int nbSplits, int shadowMapSize) { - nbShadowMaps = Math.max(Math.min(nbSplits, 4), 1); - if (nbShadowMaps != nbSplits) { - throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value : " + nbSplits); + // Ensure the number of shadow maps is within the valid range [1, 4] + if (nbSplits < 1 || nbSplits > 4) { + throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value: " + nbSplits); } + + nbShadowMaps = nbSplits; splits = new ColorRGBA(); splitsArray = new float[nbSplits + 1]; shadowCam = new Camera(shadowMapSize, shadowMapSize); @@ -151,7 +154,7 @@ protected void updateShadowCams(Camera viewCam) { ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points); shadowCam.setFrustumFar(zFar); - shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp()); + shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp(tempVec)); shadowCam.update(); shadowCam.updateViewProjection();