Hi,
In the project I’m working on, I have a scene with multiple light sources and, among them, one directional light which is used as the light for the DirectionalLightShadowRenderer.
I’ve realized two different, although maybe related, rendering issues when the object has a low poligon count, it’s big enough and is curved when configured as CastAndReceive.
I’ve created a simple test to show it. The sphere on the left hast much more segments than the one on the right and this way the rendering is better looking although still buggy.
In the front side you can see some lines that matches the segments of the object:
In the back side, as it’s enlighted by other light sources, you see clearly some more artifacts. You can also see this artifacts if using unshaded materials instead:
The testcase is as follows:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
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.scene.shape.Sphere;
import com.jme3.shadow.DirectionalLightShadowRenderer;
import com.jme3.shadow.EdgeFilteringMode;
public class BallTest extends SimpleApplication {
public static void main(String[] args) {
BallTest app = new BallTest();
app.start();
}
@Override
public void simpleInitApp() {
flyCam.setDragToRotate(true);
flyCam.setMoveSpeed(20);
flyCam.setRotationSpeed(3);
cam.setLocation(new Vector3f(0f, 60f, 60f));
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
//Main light
DirectionalLight l0=new DirectionalLight();
l0.setColor(ColorRGBA.LightGray);
l0.setDirection(new Vector3f(-0.5f, -0.5f, -0.5f).normalizeLocal());
rootNode.addLight(l0);
//Aditional light source to enlight shadowed side
DirectionalLight l1=new DirectionalLight();
l1.setColor(ColorRGBA.Yellow);
l1.setDirection(new Vector3f(0.5f, -0.5f, 0.5f).normalizeLocal());
rootNode.addLight(l1);
Material matRedLight=assetManager.loadMaterial("Materials/RedLight.j3m");
Material matRedUnshaded=assetManager.loadMaterial("Materials/RedUnshaded.j3m");
Sphere s1=new Sphere(36,36,15);
Geometry geom1=new Geometry("Sphere", s1);
geom1.setMaterial(matRedLight);
geom1.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
geom1.setLocalTranslation(16, 15, 0);
rootNode.attachChild(geom1);
Sphere s2=new Sphere(150,150,15);
Geometry geom2=new Geometry("Sphere", s2);
geom2.setMaterial(matRedLight);
geom2.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
geom2.setLocalTranslation(-16, 15, 0);
rootNode.attachChild(geom2);
//Floor
Box b = new Box(80, 1, 80);
Geometry floor = new Geometry("Box", b);
Material matFloor = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matFloor.setColor("Color", ColorRGBA.Blue);
floor.setMaterial(matFloor);
floor.setShadowMode(RenderQueue.ShadowMode.Receive);
rootNode.attachChild(floor);
DirectionalLightShadowRenderer pssm=new DirectionalLightShadowRenderer(assetManager, 2048,4);
pssm.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
pssm.setLambda(0.3f);
pssm.setLight(l0);
viewPort.addProcessor(pssm);
}
}
The material (RedLight.j3m):
Material RedLight : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
UseMaterialColors : true
Diffuse : 1.0 0.3 0.3 1.0
}
AdditionalRenderState {
}
}
I’ve found a related topic (Issues with DirectionalLightShadowRenderer rendering shadows - #6 by nehon) and tested the recommendations in it like reducing lambda, changing filtering mode and so with no luck. All of them lead to this issues although some are a little better
Thanks