Skip to content

Commit 8793765

Browse files
capdevonriccardobl
andauthored
Reduce object allocations in DirectionalLightShadowRenderer (jMonkeyEngine#2513)
* Update DirectionalLightShadowRenderer.java * DirectionalLightShadowRenderer: fix javadoc * DirectionalLightShadowRenderer: remove unused imports * DirectionalLightShadowRenderer: restored original author name * undo formatting and documentation --------- Co-authored-by: Riccardo Balbo <os@rblb.it>
1 parent c784f4b commit 8793765

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2021 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -68,7 +68,8 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer {
6868
protected float[] splitsArray;
6969
protected DirectionalLight light;
7070
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+
7273
private boolean stabilize = true;
7374

7475
/**
@@ -96,10 +97,12 @@ public DirectionalLightShadowRenderer(AssetManager assetManager, int shadowMapSi
9697
}
9798

9899
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);
102103
}
104+
105+
nbShadowMaps = nbSplits;
103106
splits = new ColorRGBA();
104107
splitsArray = new float[nbSplits + 1];
105108
shadowCam = new Camera(shadowMapSize, shadowMapSize);
@@ -150,7 +153,7 @@ protected void updateShadowCams(Camera viewCam) {
150153
ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
151154

152155
shadowCam.setFrustumFar(zFar);
153-
shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp());
156+
shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp(tempVec));
154157
shadowCam.update();
155158
shadowCam.updateViewProjection();
156159

0 commit comments

Comments
 (0)