[SOLVED] Shadow from last shadow renderer still visible on textures

Hi

I have a strange problem with shadows: I start with point light shadow renderer with a point light. So far everything do more or less what I want. Now I remove the light including the shadow renderer from room node and view port. Then I add for example a spot light shadow renderer with a spot light. Now the strange thing happen, I still see the long gone shadow from the removed point light/point light renderer.
Why is that?
Next strange thing that only happens if I change from point light to spot light. Or vise versa. As long as I remove point light / point light renderer and add it again, no problem.

Do I have to clean something when I change?

regards
christian

Hard to tell from your description, do you have a test case by any chance?

room.addLight(light);
dlsr = new PointLightShadowRenderer(app.getAssetManager(), 2048);
dlsr.setLight(light);  
dlsr.setShadowIntensity(0.6f);
dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
//...
app.getViewPort().removeProcessor(dlsr);
dlsr = null;
room.removeLight(light);
//...
room.addLight(light);
dlsr = new SpotLightShadowRenderer(app.getAssetManager(), 2048);
dlsr.setLight(light);
dlsr.setShadowIntensity(0.6f);
dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
this.app.getViewPort().addProcessor(dlsr);

Now the first point light produce some shadow depending of the stuff in the room. After removing the first one the second one produces its own shadow. But the last shadow from the first one is still there and do not change or move or something if you look around in the room. It’s just still painted.

Here some screen shots so you get the idea what I mean. This is the screenshot with the pointlight:

And this is with the spotlight, right after the point light:

I think now it is clear what I mean. I suppose just removing the dlsr is not enought (or maybe I should not do that anyway and reuse it)? In this state I have two items, if I interchange it this happens. And on interchange the above snipped is what I do.

looks like the dlsr is not properly cleaned up…
I don’t have a lot of time to look into it, but could you make a small basic test case so I could quickly test it on my side.

yes sure. I’ll come back to you with a small simple app. thanks

Voila a very quick test to show you the problem. It changes the point light with the spot after 5 second. I use a chase cam to make it easier to inspect. Hope it helps you to find the problem :smile:

Btw. I saw this only happens with point light first, spot light second. The other way around I dont see that shadow artefact.

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.input.ChaseCamera;
import com.jme3.light.PointLight;
import com.jme3.light.SpotLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.shadow.PointLightShadowRenderer;
import com.jme3.shadow.SpotLightShadowRenderer;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }
    private PointLight pointLight;
    private PointLightShadowRenderer pointLightShadow;

    @Override
    public void simpleInitApp() {
        this.flyCam.setEnabled(false);

        Box shape = new Box(10, 0.1f, 10);
        Geometry geo = new Geometry("Foo", shape);
        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setColor("Diffuse", ColorRGBA.White);
        mat.setColor("Specular", ColorRGBA.White);
        mat.setFloat("Shininess", 4f);
        geo.setMaterial(mat);
        geo.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
        rootNode.attachChild(geo);

        shape = new Box(1, 1, 1);
        geo = new Geometry("Foo", shape);
        mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setColor("Diffuse", ColorRGBA.White);
        mat.setColor("Specular", ColorRGBA.White);
        mat.setFloat("Shininess", 4f);
        geo.setMaterial(mat);
        geo.setLocalTranslation(1, 0, 1);
        geo.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
        rootNode.attachChild(geo);

        ChaseCamera chaseCam = new ChaseCamera(cam, geo, inputManager);

        pointLight = new PointLight();
        pointLight.setRadius(200);

        pointLight.setPosition(new Vector3f(2, 2, 2));
        rootNode.addLight(pointLight);
        pointLightShadow = new PointLightShadowRenderer(assetManager, 2048);
        pointLightShadow.setLight(pointLight);
        pointLightShadow.setShadowIntensity(0.6f);
        pointLightShadow.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
        viewPort.addProcessor(pointLightShadow);


    }
    private float total;

    @Override
    public void simpleUpdate(float tpf) {
        total += tpf;
        if (total > 5) {

            if (pointLightShadow != null) {
                rootNode.removeLight(pointLight);
                viewPort.removeProcessor(pointLightShadow);
                pointLightShadow = null;

                SpotLight spotLight = new SpotLight();
                spotLight.setSpotInnerAngle(FastMath.DEG_TO_RAD * 30);
                spotLight.setSpotOuterAngle(FastMath.DEG_TO_RAD * 70);
                spotLight.setSpotRange(100);
                spotLight.setDirection(new Vector3f(10, -1, 10));

                spotLight.setPosition(new Vector3f(-10, 2, -10));
                rootNode.addLight(spotLight);
                SpotLightShadowRenderer spotLightShadow = new SpotLightShadowRenderer(assetManager, 2048);
                spotLightShadow.setLight(spotLight);
                spotLightShadow.setShadowIntensity(0.6f);
                spotLightShadow.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
                viewPort.addProcessor(spotLightShadow);
            }
        }
    }
}
1 Like

Ok this is what I have with your test case :
Imgur
and
Imgur

Looks as intended to me.
Are you using 3.0 or 3.1
I tested with 3.1.

many thanks. yes it seems that it is solved with 3.1. I’m using 3.0 on linux as it is marked stable :smile:
Would you propose to use 3.1? Are there many things which I would have to adjust?

no… this means I’d rather test with 3.0 and release a patch version…
Going to 3.1 can break many things.

1 Like

Just to show you what I see :slight_smile: Even the shadow seems not long enough, yours look much longer.

Your project seems to be (from here, I could be totally wrong) at it’s starting phase… seems to me it’s best to move to 3.1 early on.

@loopies: Yes sure it is in the starting phase. I have now more or less may game mechanic implemented, not yet finished with every detail. I also was thinking of using 3.1 (that’s why I asked @nehon), but hesitate a little, as I then have maybe to bother with other issues. Known issues are better than unknown issues :wink:

And maybe other could profit from a possible fix as well?

1 Like

I’m a bit surprised that the shadow doesn’t look the same though…
If you can switch to 3.1, go ahead. 3.1 is stable enough IMO. It’s just that migrating from 3.0 to 3.1 is not that obvious.

Ok migrating seems to be a piece of cake for my stuff.
And the problem is solved with 3.1 like you said :smile:

1 Like

cool :wink: