Hey I'm new to JME and I'm just trying to figure out how to get shadows working properly. The first thing I discovered was that if I didn't have ZBuffering enabled then my Box was rendered incorrectly (meaning that parts which shouldn't be visible were). Enabling ZBuffering fixed that problem. After that I wanted to enable shadows so I followed various tutorials on the wiki. Finally, I ended up with the following code:
@Override
protected void initGame() {
root = new Node("root");
Node occluders = new Node("occluders");
root.attachChild(occluders);
ZBufferState buffer = display.getRenderer().createZBufferState();
buffer.setEnabled(true);
buffer.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
root.setRenderState(buffer);
passManager = new BasicPassManager();
shadowPass = new ShadowedRenderPass();
shadowPass.setEnabled(true);
shadowPass.setRenderShadows(true);
shadowPass.setLightingMethod(LightingMethod.Additive);
shadowPass.addOccluder(occluders);
shadowPass.add(root);
passManager.add(shadowPass);
RenderPass renderPass = new RenderPass();
renderPass.add(root);
passManager.add(renderPass);
DirectionalLight light = new DirectionalLight();
light.setEnabled(true);
light.setShadowCaster(true);
light.setDirection(new Vector3f(0, 0, -.5f));
lightState = display.getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
root.setRenderState(lightState);
initBox(occluders);
root.updateRenderState();
}
The goal of course is to have the Box I create in initBox rendered with all sides being lit except its back. Unfortunately the result is the top is lit -- and I can't seem to change this by changing the direction of the DirectionalLight. However, I can fix things by turning off ZBuffering. I say fix but really it's just trades one problem for another because as before the box is no longer rendered correctly but at least the shadow is correct.
Can anyone help me out? Is there something about ZBuffering I'm not aware of (very likely)? Also, I ultimately want to have a cast shadow is that supported by JME or do I have to implement that on top of JME's lighting system?
Thanks! Look forward to getting unblocked and productive with JME!