Hi!
I have decided to use shadows in my application and I have noticed some black rectangles, where they should not be. Looks like there is a bug in the PointLightShadowRenderer
, or I use it incorrectly. I will provide a simple test (JME 3.2):
package jme3test.light;
import com.jme3.app.SimpleApplication;
import com.jme3.light.PointLight;
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.shadow.PointLightShadowRenderer;
public class TestPointLightShadow extends SimpleApplication {
private final boolean chaseLight = true;
private final float offset = -20f;
private PointLight pointLight;
private Geometry box;
private float x = offset;
public static void main(String[] args) {
TestPointLightShadow app = new TestPointLightShadow();
app.start();
}
@Override
public void simpleInitApp() {
box = new Geometry("Box", new Box(1f, 1f, 1f));
Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
material.setColor("Diffuse", ColorRGBA.White);
box.setMaterial(material);
box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
box.setLocalTranslation(x, 0, 0);
rootNode.attachChild(box);
pointLight = new PointLight();
pointLight.setColor(ColorRGBA.White.mult(1.8f));
pointLight.setRadius(30f);
rootNode.addLight(pointLight);
pointLight.setPosition(new Vector3f(offset - 2f, 0, 0));
cam.setLocation(new Vector3f(offset - 4f, 0, 0));
cam.lookAtDirection(Vector3f.UNIT_X, Vector3f.UNIT_Y);
flyCam.setMoveSpeed(1f);
PointLightShadowRenderer plsr = new PointLightShadowRenderer(assetManager, 1024);
plsr.setLight(pointLight);
viewPort.addProcessor(plsr);
}
@Override
public void simpleUpdate(float tpf) {
if (chaseLight) {
pointLight.setPosition(cam.getLocation().add(2, 0, 0));
} else {
x -= tpf / 10f;
box.setLocalTranslation(x, 0, 0);
}
}
}
Here we have a single white box with lighting material. There is a white point light in front of it. Camera is in front of the box (point light is between camera and box). Box casts and receives shadows. We use renderer (not filter) for shadows.
Test allows to run it in 2 modes: chaseLight=true
, when point light chases the camera (try to get closer to the box to see the bug) and chaseLight=false
, when box moves towards the camera (you will see bug automatically). In both cases, when point light is close to a box, there is a dark rectangle on the box. The closer the point light to the box surface, the smaller the rectangle. As we have only a single geometry in the scene, there should not be any shadow, but we have it from somewhere! Bug is reproduced, when shadow mode is CastAndReceive
. It is not shown for other shadow modes.
Test also has offset
. It just shifts the box, light and camera at the same distance. Bug is reproduced only if offset is within point light radius (a little bit less, I think it also depends on the box size). If to set offset to 30, bug will not be reproduced. It looks like PointLightShadowRenderer
uses PointLight
position using local space system instead of world one for some calculations, and casts box on top of itself.
Can you please confirm that this is a bug?
Thank you!