Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1867 (LightFilter gets applied even if not needed) #1872

Merged
merged 7 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions jme3-core/src/main/java/com/jme3/light/NullLightFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2009-2022 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jme3.light;

import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry;
/**
* NullLightFilter does nothing. Used when you want
* to disable the light filter
*
* @author Michael Zuegg
*/
public class NullLightFilter implements LightFilter {
@Override
public void setCamera(Camera camera) {

}

@Override
public void filterLights(Geometry geometry, LightList filteredLightList) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import com.jme3.asset.AssetManager;
import com.jme3.export.*;
import com.jme3.light.LightFilter;
import com.jme3.light.NullLightFilter;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
Expand Down Expand Up @@ -77,7 +79,7 @@
public abstract class AbstractShadowRenderer implements SceneProcessor, Savable, JmeCloneable, Cloneable {

protected static final Logger logger = Logger.getLogger(AbstractShadowRenderer.class.getName());

private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
protected int nbShadowMaps = 1;
protected float shadowMapSize;
protected float shadowIntensity = 0.7f;
Expand Down Expand Up @@ -443,10 +445,14 @@ protected void renderShadowMap(int shadowMapIndex) {
renderManager.getRenderer().clearBuffers(true, true, true);
renderManager.setForcedRenderState(forcedRenderState);

// render shadow casters to shadow map
// render shadow casters to shadow map and disables the lightfilter
LightFilter tmpLightFilter = renderManager.getLightFilter();
renderManager.setLightFilter(NULL_LIGHT_FILTER);
viewPort.getQueue().renderShadowQueue(shadowMapOccluders, renderManager, shadowCam, true);
renderManager.setLightFilter(tmpLightFilter);
renderManager.setForcedRenderState(null);
}

boolean debugfrustums = false;

public void displayFrustum() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
package com.jme3.shadow;

import com.jme3.asset.AssetManager;
import com.jme3.light.LightFilter;
import com.jme3.light.NullLightFilter;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.post.SceneProcessor;
Expand Down Expand Up @@ -59,7 +61,7 @@
*/
@Deprecated
public class BasicShadowRenderer implements SceneProcessor {

private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
private RenderManager renderManager;
private ViewPort viewPort;
final private FrameBuffer shadowFB;
Expand Down Expand Up @@ -196,7 +198,11 @@ public void postQueue(RenderQueue rq) {

r.setFrameBuffer(shadowFB);
r.clearBuffers(true, true, true);
// render shadow casters to shadow map and disables the lightfilter
LightFilter tmpLightFilter = renderManager.getLightFilter();
renderManager.setLightFilter(NULL_LIGHT_FILTER);
viewPort.getQueue().renderShadowQueue(shadowOccluders, renderManager, shadowCam, true);
renderManager.setLightFilter(tmpLightFilter);
r.setFrameBuffer(viewPort.getOutputFrameBuffer());

renderManager.setForcedMaterial(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
package com.jme3.shadow;

import com.jme3.asset.AssetManager;
import com.jme3.light.LightFilter;
import com.jme3.light.NullLightFilter;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Matrix4f;
Expand Down Expand Up @@ -75,7 +77,7 @@
*/
@Deprecated
public class PssmShadowRenderer implements SceneProcessor {

private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
/**
* <code>FilterMode</code> specifies how shadows are filtered
* @deprecated use {@link EdgeFilteringMode}
Expand Down Expand Up @@ -448,8 +450,11 @@ public void postQueue(RenderQueue rq) {
r.setFrameBuffer(shadowFB[i]);
r.clearBuffers(true, true, true);

// render shadow casters to shadow map
// render shadow casters to shadow map and disables the lightfilter
LightFilter tmpLightFilter = renderManager.getLightFilter();
renderManager.setLightFilter(NULL_LIGHT_FILTER);
viewPort.getQueue().renderShadowQueue(splitOccluders, renderManager, shadowCam, true);
renderManager.setLightFilter(tmpLightFilter);
}
debugfrustums = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import com.jme3.asset.AssetManager;
import com.jme3.export.*;
import com.jme3.light.LightFilter;
import com.jme3.light.NullLightFilter;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
Expand Down Expand Up @@ -75,7 +77,7 @@
* @author Julien Seinturier - COMEX SA - <a href="http://www.seinturier.fr">http://www.seinturier.fr</a>
*/
public abstract class AbstractShadowRendererVR implements SceneProcessor, Savable {

private static final LightFilter NULL_LIGHT_FILTER = new NullLightFilter();
protected int nbShadowMaps = 1;
protected float shadowMapSize;
protected float shadowIntensity = 0.7f;
Expand Down Expand Up @@ -440,8 +442,11 @@ protected void renderShadowMap(int shadowMapIndex) {
renderManager.getRenderer().clearBuffers(true, true, true);
renderManager.setForcedRenderState(forcedRenderState);

// render shadow casters to shadow map
// render shadow casters to shadow map and disables the lightfilter
LightFilter tmpLightFilter = renderManager.getLightFilter();
renderManager.setLightFilter(NULL_LIGHT_FILTER);
viewPort.getQueue().renderShadowQueue(shadowMapOccluders, renderManager, shadowCam, true);
renderManager.setLightFilter(tmpLightFilter);
renderManager.setForcedRenderState(null);
}
boolean debugfrustums = false;
Expand Down