Artefacts with point light and shadwos

Hi @nehon

Here my test case, just zoom in out using your mouse wheel in this angel and you will see the artefacts. Best thing I could reproduce the issue on the same distance from zero position than in my room :smile: without any special texture or object.

package mygame;

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

/**
 * test
 *
 * @author normenhansen
 */
public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {

        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        geom.setMaterial(mat);
        mat.setColor("Diffuse", ColorRGBA.White);
        mat.setColor("Specular", ColorRGBA.White);
        mat.setFloat("Shininess", 64f);
        geom.setMaterial(mat);
        geom.setLocalTranslation(-12, 0, 5);
        geom.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
        rootNode.attachChild(geom);

        b = new Box(1, 1, 1);
        geom = new Geometry("Box", b);
        mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        geom.setMaterial(mat);
        mat.setColor("Diffuse", ColorRGBA.White);
        mat.setColor("Specular", ColorRGBA.White);
        mat.setFloat("Shininess", 64f);
        geom.setMaterial(mat);
        geom.setLocalTranslation(-8, 0, 5);
        geom.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
        rootNode.attachChild(geom);

        b = new Box(0.25f, 1, 0.25f);
        geom = new Geometry("Box", b);
        mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        geom.setMaterial(mat);
        mat.setColor("Diffuse", ColorRGBA.White);
        mat.setColor("Specular", ColorRGBA.White);
        mat.setFloat("Shininess", 64f);
        geom.setMaterial(mat);
        geom.setLocalTranslation(-9.5f, 0, 5);
        geom.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
        rootNode.attachChild(geom);

        ChaseCamera camera = new ChaseCamera(getCamera(), geom, getInputManager());
        camera.setRotationSpeed(3);
        camera.setDefaultHorizontalRotation(-40 * FastMath.DEG_TO_RAD);
        camera.setDefaultVerticalRotation(25 * FastMath.DEG_TO_RAD);
        camera.setMinDistance(4);
        camera.setDefaultDistance(4.5f);
        camera.setMaxVerticalRotation(90 * FastMath.DEG_TO_RAD);
        camera.setMinVerticalRotation(-90 * FastMath.DEG_TO_RAD);

        PointLight light = new PointLight();
        light.setRadius(10);
        PointLightShadowRenderer pointLightShadow
                = new PointLightShadowRenderer(getAssetManager(), 512);
        pointLightShadow.setLight(light);
        pointLightShadow.setShadowIntensity(1f);
        pointLightShadow.setShadowCompareMode(CompareMode.Hardware);
        getViewPort().addProcessor(pointLightShadow);

        light.setPosition(new Vector3f(-10f, 0, 5));

        getRootNode().addLight(light);

    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}

I hope you see the same, else hmmmm, yeah no clue then… I have it on my laptop and on my desktop. And yeah a orbiting camera as usual to make your life little easier to inspect it.

EDIT: If you short the “thin” object to let’s say 0.5f then you see as well that this small object between the two bigger cubes is the one which produce those artefacts on the surface, as the artefacts do have the same height. Hope you understand what I mean.

cool thanks, will look into it

jME 3.1 in case you wonder :smile:

I don’t :wink:

Not everybody can…
And deferred shading done “right” is not an easy task.

Not everybody can write a game, but we have a forum full of ppl who are trying and have some results. In my opinion for every programmer it is only a matter of determination to learn shaders. Rewriting existing forward rendering into deferred was easier than I thought. You have the whole math and calculations in stock shaders, all you need to do is to is to fill g-buffer in first pass, and then draw the scene using lights and data stored in g-buffer.

1 Like

Any news on this topic? Can you reproduce the problem with my test I posted?

Didn’t have chance yet.
I will.

I have to say it’s a pretty nice test case, thanks.
I think it’s pure z-fighting, it might be resolved by playing with the polygon offset… but there is no easy API to do it.
I’ll see what I can do.

ok…it’s an old issue actually, that we have also with the dirrectional shadow renderer.
When the shadow cam is aligned with the shadowed surface it does this flickering.
Since the point light shadow renderer create axis aligned shadow cams, if you have your scene axis aligned (wich is very likely with the kind of building interrior scene you have) you’ll have the issue.
I’m going to try to fix this, now that I have a reproductible test case, but in the mean time, an easy workaround is to slightly rotate your root node around the Y axis like this

     getRootNode().rotate(0,0.00001f, 0);

Make sure the rotation is very small.

1 Like

wow! thanks a lot. I’ll try tomorrow morning :smile:

Works! I did a bigger rotation until all flickering was gone.

app.getRootNode().rotate(0,0.001f, 0);

Thanks a lot.

I’m working on a solution and I may have found something. Incidentally, it may solve a very old issue in the shadow implementation… not sure yet though.

2 Likes