|
1 | 1 | /* |
2 | | - * Copyright (c) 2009-2021 jMonkeyEngine |
| 2 | + * Copyright (c) 2009-2025 jMonkeyEngine |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -68,7 +68,8 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer { |
68 | 68 | protected float[] splitsArray; |
69 | 69 | protected DirectionalLight light; |
70 | 70 | protected Vector3f[] points = new Vector3f[8]; |
71 | | - //Holding the info for fading shadows in the far distance |
| 71 | + protected final Vector3f tempVec = new Vector3f(); |
| 72 | + |
72 | 73 | private boolean stabilize = true; |
73 | 74 |
|
74 | 75 | /** |
@@ -96,10 +97,12 @@ public DirectionalLightShadowRenderer(AssetManager assetManager, int shadowMapSi |
96 | 97 | } |
97 | 98 |
|
98 | 99 | private void init(int nbSplits, int shadowMapSize) { |
99 | | - nbShadowMaps = Math.max(Math.min(nbSplits, 4), 1); |
100 | | - if (nbShadowMaps != nbSplits) { |
101 | | - throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value : " + nbSplits); |
| 100 | + // Ensure the number of shadow maps is within the valid range [1, 4] |
| 101 | + if (nbSplits < 1 || nbSplits > 4) { |
| 102 | + throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value: " + nbSplits); |
102 | 103 | } |
| 104 | + |
| 105 | + nbShadowMaps = nbSplits; |
103 | 106 | splits = new ColorRGBA(); |
104 | 107 | splitsArray = new float[nbSplits + 1]; |
105 | 108 | shadowCam = new Camera(shadowMapSize, shadowMapSize); |
@@ -150,7 +153,7 @@ protected void updateShadowCams(Camera viewCam) { |
150 | 153 | ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points); |
151 | 154 |
|
152 | 155 | shadowCam.setFrustumFar(zFar); |
153 | | - shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp()); |
| 156 | + shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp(tempVec)); |
154 | 157 | shadowCam.update(); |
155 | 158 | shadowCam.updateViewProjection(); |
156 | 159 |
|
|
0 commit comments