Skip to content

Commit d3efabc

Browse files
capdevonriccardobl
andauthored
Reduce object allocations in SpotLightShadowRenderer (#2515)
* Update SpotLightShadowRenderer.java * SpotLightShadowRenderer: fix javadoc * SpotLightShadowRenderer: fix link * SpotLightShadowRenderer: revert points cloning * SpotLightShadowRenderer: restored original author name * revert formatting and docs * improve clarity * reapply tempVec diff that was reverted by mistake --------- Co-authored-by: Riccardo Balbo <os@rblb.it>
1 parent 8b7e799 commit d3efabc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 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
@@ -65,9 +65,9 @@ public class SpotLightShadowRenderer extends AbstractShadowRenderer {
6565

6666
protected Camera shadowCam;
6767
protected SpotLight light;
68-
protected Vector3f[] points = new Vector3f[8];
69-
//Holding the info for fading shadows in the far distance
70-
68+
protected final Camera[] tempCams = new Camera[1];
69+
protected final Vector3f[] points = new Vector3f[8];
70+
protected final Vector3f tempVec = new Vector3f();
7171

7272
/**
7373
* Used for serialization use SpotLightShadowRenderer#SpotLightShadowRenderer(AssetManager assetManager, int shadowMapSize)
@@ -100,7 +100,8 @@ private void init(int shadowMapSize) {
100100
protected void initFrustumCam() {
101101
Camera viewCam = viewPort.getCamera();
102102
frustumCam = viewCam.clone();
103-
frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom());
103+
frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(),
104+
viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom());
104105
}
105106

106107
/**
@@ -140,7 +141,7 @@ protected void updateShadowCams(Camera viewCam) {
140141
//shadowCam.setDirection(direction);
141142

142143
shadowCam.setFrustumPerspective(light.getSpotOuterAngle() * FastMath.RAD_TO_DEG * 2.0f, 1, 1f, light.getSpotRange());
143-
shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp());
144+
shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp(tempVec));
144145
shadowCam.setLocation(light.getPosition());
145146

146147
shadowCam.update();
@@ -158,10 +159,9 @@ protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList sha
158159
@Override
159160
protected void getReceivers(GeometryList lightReceivers) {
160161
lightReceivers.clear();
161-
Camera[] cameras = new Camera[1];
162-
cameras[0] = shadowCam;
162+
tempCams[0] = shadowCam;
163163
for (Spatial scene : viewPort.getScenes()) {
164-
ShadowUtil.getLitGeometriesInViewPort(scene, viewPort.getCamera(), cameras, RenderQueue.ShadowMode.Receive, lightReceivers);
164+
ShadowUtil.getLitGeometriesInViewPort(scene, viewPort.getCamera(), tempCams, RenderQueue.ShadowMode.Receive, lightReceivers);
165165
}
166166
}
167167

0 commit comments

Comments
 (0)