Skip to content

Commit 5d1ee26

Browse files
authored
Fix #1867 (LightFilter gets applied even if not needed) (#1872)
* Add NullLightFilter.java * Add usage of null light filter when rendering shadowmaps * Fix formatting * Make static NullLightFilter final * Fix formatting and author
1 parent 8de08ad commit 5d1ee26

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2009-2022 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package com.jme3.light;
34+
35+
import com.jme3.renderer.Camera;
36+
import com.jme3.scene.Geometry;
37+
/**
38+
* NullLightFilter does nothing. Used when you want
39+
* to disable the light filter
40+
*
41+
* @author Michael Zuegg
42+
*/
43+
public class NullLightFilter implements LightFilter {
44+
@Override
45+
public void setCamera(Camera camera) {
46+
47+
}
48+
49+
@Override
50+
public void filterLights(Geometry geometry, LightList filteredLightList) {
51+
52+
}
53+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import com.jme3.asset.AssetManager;
3535
import com.jme3.export.*;
36+
import com.jme3.light.LightFilter;
37+
import com.jme3.light.NullLightFilter;
3638
import com.jme3.material.Material;
3739
import com.jme3.material.RenderState;
3840
import com.jme3.math.ColorRGBA;
@@ -77,7 +79,7 @@
7779
public abstract class AbstractShadowRenderer implements SceneProcessor, Savable, JmeCloneable, Cloneable {
7880

7981
protected static final Logger logger = Logger.getLogger(AbstractShadowRenderer.class.getName());
80-
82+
private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
8183
protected int nbShadowMaps = 1;
8284
protected float shadowMapSize;
8385
protected float shadowIntensity = 0.7f;
@@ -443,10 +445,14 @@ protected void renderShadowMap(int shadowMapIndex) {
443445
renderManager.getRenderer().clearBuffers(true, true, true);
444446
renderManager.setForcedRenderState(forcedRenderState);
445447

446-
// render shadow casters to shadow map
448+
// render shadow casters to shadow map and disables the lightfilter
449+
LightFilter tmpLightFilter = renderManager.getLightFilter();
450+
renderManager.setLightFilter(NULL_LIGHT_FILTER);
447451
viewPort.getQueue().renderShadowQueue(shadowMapOccluders, renderManager, shadowCam, true);
452+
renderManager.setLightFilter(tmpLightFilter);
448453
renderManager.setForcedRenderState(null);
449454
}
455+
450456
boolean debugfrustums = false;
451457

452458
public void displayFrustum() {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
package com.jme3.shadow;
3333

3434
import com.jme3.asset.AssetManager;
35+
import com.jme3.light.LightFilter;
36+
import com.jme3.light.NullLightFilter;
3537
import com.jme3.material.Material;
3638
import com.jme3.math.Vector3f;
3739
import com.jme3.post.SceneProcessor;
@@ -59,7 +61,7 @@
5961
*/
6062
@Deprecated
6163
public class BasicShadowRenderer implements SceneProcessor {
62-
64+
private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
6365
private RenderManager renderManager;
6466
private ViewPort viewPort;
6567
final private FrameBuffer shadowFB;
@@ -196,7 +198,11 @@ public void postQueue(RenderQueue rq) {
196198

197199
r.setFrameBuffer(shadowFB);
198200
r.clearBuffers(true, true, true);
201+
// render shadow casters to shadow map and disables the lightfilter
202+
LightFilter tmpLightFilter = renderManager.getLightFilter();
203+
renderManager.setLightFilter(NULL_LIGHT_FILTER);
199204
viewPort.getQueue().renderShadowQueue(shadowOccluders, renderManager, shadowCam, true);
205+
renderManager.setLightFilter(tmpLightFilter);
200206
r.setFrameBuffer(viewPort.getOutputFrameBuffer());
201207

202208
renderManager.setForcedMaterial(null);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
package com.jme3.shadow;
3333

3434
import com.jme3.asset.AssetManager;
35+
import com.jme3.light.LightFilter;
36+
import com.jme3.light.NullLightFilter;
3537
import com.jme3.material.Material;
3638
import com.jme3.math.ColorRGBA;
3739
import com.jme3.math.Matrix4f;
@@ -75,7 +77,7 @@
7577
*/
7678
@Deprecated
7779
public class PssmShadowRenderer implements SceneProcessor {
78-
80+
private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
7981
/**
8082
* <code>FilterMode</code> specifies how shadows are filtered
8183
* @deprecated use {@link EdgeFilteringMode}
@@ -448,8 +450,11 @@ public void postQueue(RenderQueue rq) {
448450
r.setFrameBuffer(shadowFB[i]);
449451
r.clearBuffers(true, true, true);
450452

451-
// render shadow casters to shadow map
453+
// render shadow casters to shadow map and disables the lightfilter
454+
LightFilter tmpLightFilter = renderManager.getLightFilter();
455+
renderManager.setLightFilter(NULL_LIGHT_FILTER);
452456
viewPort.getQueue().renderShadowQueue(splitOccluders, renderManager, shadowCam, true);
457+
renderManager.setLightFilter(tmpLightFilter);
453458
}
454459
debugfrustums = false;
455460

jme3-vr/src/main/java/com/jme3/shadow/AbstractShadowRendererVR.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import com.jme3.asset.AssetManager;
3636
import com.jme3.export.*;
37+
import com.jme3.light.LightFilter;
38+
import com.jme3.light.NullLightFilter;
3739
import com.jme3.material.Material;
3840
import com.jme3.material.RenderState;
3941
import com.jme3.math.ColorRGBA;
@@ -75,7 +77,7 @@
7577
* @author Julien Seinturier - COMEX SA - <a href="http://www.seinturier.fr">http://www.seinturier.fr</a>
7678
*/
7779
public abstract class AbstractShadowRendererVR implements SceneProcessor, Savable {
78-
80+
private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
7981
protected int nbShadowMaps = 1;
8082
protected float shadowMapSize;
8183
protected float shadowIntensity = 0.7f;
@@ -440,8 +442,11 @@ protected void renderShadowMap(int shadowMapIndex) {
440442
renderManager.getRenderer().clearBuffers(true, true, true);
441443
renderManager.setForcedRenderState(forcedRenderState);
442444

443-
// render shadow casters to shadow map
445+
// render shadow casters to shadow map and disables the lightfilter
446+
LightFilter tmpLightFilter = renderManager.getLightFilter();
447+
renderManager.setLightFilter(NULL_LIGHT_FILTER);
444448
viewPort.getQueue().renderShadowQueue(shadowMapOccluders, renderManager, shadowCam, true);
449+
renderManager.setLightFilter(tmpLightFilter);
445450
renderManager.setForcedRenderState(null);
446451
}
447452
boolean debugfrustums = false;

0 commit comments

Comments
 (0)