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