Several ShadowFilter

Hi, I just noticed, that only one Shadow Filter is shown, when I another one, it doesn’t show up until I remove the first.
Why is that?

do you have a testcase maybe?

Yup.
Sorry if the code is not written in a good style but I’m tired as hell and don’t have much time.
So as you see there are two lights (spot and directional) and shadow filters for each.
Both shadow filters are added, but only the spotLight shadow is working.
If you disable it, the directional light shadow will work.
Only one can work at one time, test it by commenting the line fpp.addFilter … of one of the shadows
[java]
public class Main extends SimpleApplication {
SpotLightShadowFilter spotLightShadowFilter;
DirectionalLightShadowFilter directionalLightShadowFilter;
SpotLight spotLight = new SpotLight();
DirectionalLight directionalLight = new DirectionalLight();
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
createSphere(10, 0, 0);
createSphere(0, 10, 0);
createSphere(0, 0, 10);

    createSphere(10, 10, 0);
    createSphere(0, 10, 10);
    createSphere(10, 0, 10);

    createSphere(10, -10, 0);
    createSphere(0, 10, -10);
    createSphere(10, 0, -10);

    createSphere(-10, 10, 0);
    createSphere(-10, 10, -10);
    createSphere(0, -10, 10);
    createSphere(-10, 0, 10);
    createSphere(10, 0, -10);

    createSphere(-10, 0, 0);
    createSphere(0, -10, 0);
    createSphere(0, 0, -10);

    createSphere(-10, -10, 0);
    createSphere(0, -10, -10);
    createSphere(-10, 0, -10);

    createSphere(-10, -10, -10);
    createSphere(10, -10, -10);
    createSphere(10, 10, -10);

    createSphere(10, 10, 10);
    createSphere(10, -10, 10);
    createSphere(10, 10, -10);
    createSphere(-10, 10, -10);
    //Box 1
    Geometry b1 = new Geometry("b1", new Box(40, .5f, 40));
    b1.setLocalTranslation(0, -40, 0);
    createBox(b1);
    //Box 2
    Geometry b2 = new Geometry("b2", new Box(40, .5f, 40));
    b2.setLocalTranslation(0, 40, 0);
    createBox(b2);
    //Box 1
    Geometry b3 = new Geometry("b1", new Box(.5f, 40, 40));
    b3.setLocalTranslation(40, 0, 0);
    createBox(b3);
    //Box 2
    Geometry b4 = new Geometry("b2", new Box(.5f, 40, 40));
    b4.setLocalTranslation(-40, 0, 0);

    directionalLight.setColor(ColorRGBA.White);
    spotLight.setColor(ColorRGBA.Yellow);
    spotLight.setSpotRange(200);
    spotLight.setSpotInnerAngle(.1f);
    spotLight.setSpotOuterAngle(.3f);
    rootNode.addLight(spotLight);
    rootNode.addLight(directionalLight);
    spotLight.setDirection(new Vector3f(.2f, .2f, .2f));
    directionalLight.setDirection(new Vector3f(.2f, .2f, .2f));
    spotLight.setPosition(new Vector3f(0, 0, 0));
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    spotLightShadowFilter = new SpotLightShadowFilter(assetManager, 512);
    spotLightShadowFilter.setLight(spotLight);
    fpp.addFilter(spotLightShadowFilter);
    directionalLightShadowFilter = new DirectionalLightShadowFilter(assetManager, 512, 4);
    directionalLightShadowFilter.setLight(directionalLight);
    fpp.addFilter(directionalLightShadowFilter);
    flyCam.setDragToRotate(true);
    flyCam.setMoveSpeed(200);
    rootNode.addLight(new AmbientLight());
    viewPort.addProcessor(fpp);
}
@Override
public void simpleUpdate(float tpf) {
    spotLight.setDirection(cam.getDirection());
    spotLight.setPosition(rootNode.getChild(4).getLocalTranslation().add(0, 3, 0));
    //TODO: add update code
}
private void createSphere(int x, int y, int z) {
    Sphere b = new Sphere(33, 33, 1.8f);
    Geometry geom = new Geometry("Box", b);
    geom.setLocalTranslation(x, y, z);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setColor("Diffuse", ColorRGBA.LightGray);
    geom.setMaterial(mat);
    geom.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(geom);
}
private void createBox(Geometry geom) {
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setColor("Diffuse", ColorRGBA.LightGray);
    geom.setMaterial(mat);
    geom.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(geom);
}

}
[/java]
Thank you.

2 Likes

thanks I’ll look into it

1 Like

you need to set the first filter to not flush the shadow queues
spotLightShadowFilter.setFlushShadowQueues(false);

the queues are populated each frame and flushed once rendered. Here since you want to render the shadowed geometry twice, the first filter must not flush the queues or else the second one has no geometry to render.

1 Like

Didn’t know that.
Cool, thank you very very much!