Multiple Point/SpotLightShadowMapping Bug

Hi, It seems that there is an issue when using multiple PointLightShadow or SpotLightShadow, where the resulting shadow of the second one (only tested with two at a time) is way darker that it is supposed to be and may be considered just black.
This issue is not present when using multiple DirectionnalShadow.

  • this can be easily reproduced by adding a second shadow effect of the same type in the jme tests (ex: TestPointLightShadows).

On all the processors except the last one you have to call processor.setFlushShadowQueues(false)

@ nehon: This was done.

After some tests, it seems that the first processor is never flushed so the “color mapping intensity” is readded each frames. This cant be easily seen by setting the shadow intensity to a very low one like 0.01f and it will be possible to see the intensity of the shadow grow each frame.

@teencrusher said: @ nehon: This was done.

After some tests, it seems that the first processor is never flushed so the “color mapping intensity” is readded each frames. This cant be easily seen by setting the shadow intensity to a very low one like 0.01f and it will be possible to see the intensity of the shadow grow each frame.


ok sorry my bad, I just didn’t read properly your issue.
I’ll test it.

@ nehon here’s an easy sample for your tests :
[java]/*

import com.jme3.app.SimpleApplication;
import com.jme3.light.PointLight;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.shadow.PointLightShadowFilter;
import com.jme3.shadow.PointLightShadowRenderer;

public class Main extends SimpleApplication {
public static final int SHADOWMAP_SIZE = 512;

public static void main(String[] args) {
    Main app = new Main();
    app.start();
}
Node lightNode;
PointLightShadowRenderer plsr;
PointLightShadowFilter plsf;

@Override
public void simpleInitApp() {
    FilterPostProcessor fpp;
    flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(0.040581334f, 1.7745866f, 6.155161f));
    cam.setRotation(new Quaternion(4.3868728E-5f, 0.9999293f, -0.011230096f, 0.0039059948f));


    Node scene = (Node) assetManager.loadModel("Models/Test/CornellBox.j3o");
    scene.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(scene);
    rootNode.getChild("Cube").setShadowMode(RenderQueue.ShadowMode.Receive);
    lightNode = (Node) rootNode.getChild("Lamp");
    Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setShadowMode(RenderQueue.ShadowMode.Off);
    lightNode.attachChild(lightMdl);
    //lightMdl.setLocalTranslation(lightNode.getLocalTranslation());


    Geometry box = new Geometry("box", new Box(0.2f, 0.2f, 0.2f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    box.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(box);
    box.setLocalTranslation(-1f, 0.5f, -2);


    plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    plsr.setLight((PointLight) scene.getLocalLightList().get(0));
    plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsr.setFlushQueues(false);
    plsr.setShadowIntensity(0.01f);
    //plsr.displayFrustum();
    plsr.displayDebug();
    viewPort.addProcessor(plsr);
    
    
    plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    plsf.setLight((PointLight) scene.getLocalLightList().get(0));     
    plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    //plsf.setFlushQueues(false);
    plsf.setEnabled(false);


    fpp = new FilterPostProcessor(assetManager);
    
    fpp.addFilter(plsf);
    viewPort.addProcessor(fpp);
    


    PointLight pl = new PointLight();
    pl.setPosition(new Vector3f(0, 0.3f, 0.3f));
    pl.setRadius(5);
    rootNode.addLight(pl);

//
Geometry lightMdl2 = new Geometry(“Light2”, new Sphere(10, 10, 0.1f));
// //Geometry lightMdl = new Geometry(“Light”, new Box(.1f,.1f,.1f));
lightMdl2.setMaterial(assetManager.loadMaterial(“Common/Materials/RedColor.j3m”));
lightMdl2.setShadowMode(RenderQueue.ShadowMode.Off);
rootNode.attachChild(lightMdl2);
lightMdl2.setLocalTranslation(pl.getPosition());
PointLightShadowRenderer plsr2 = new PointLightShadowRenderer(assetManager, 512);
plsr2.setShadowIntensity(0.3f);
plsr2.setLight(pl);
plsr2.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
plsr2.setFlushQueues(true);

// // plsr.displayDebug();
viewPort.addProcessor(plsr2);

    plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    plsf.setLight(pl);     
    plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsf.setEnabled(false);


    fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(plsf);
    viewPort.addProcessor(fpp);
          
    //ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
}

@Override
public void simpleUpdate(float tpf) {

// lightNode.move(FastMath.cos(tpf) * 0.4f, 0, FastMath.sin(tpf) * 0.4f);
}
}[/java]

1 Like

Thanks for the test case.
it looks like the queue is never flushed.

ok It should be fixed now.
Thanks again for reporting the issue and the test case

1 Like

Thanks, it worked.