I’ve started using DirectionalLightShadowRenderer, and I’ve got a number of bugs. For instance, when I remove an object from the scene, its shadow persists. This is demonstrated by the test app below. Press the ‘N’ key to toggle the logo box in and out of the scene. Surely I must be doing something wrong, but what is it?
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.DirectionalLightShadowFilter;
import com.jme3.shadow.DirectionalLightShadowRenderer;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.texture.Texture;
/**
-
A simple JME3 app to demonstrate shadow rendering issues.
*/
public class Main
extends SimpleApplication
implements ActionListener {static final int shadowMapSize = 1024;
static final int nbSplits = 3;
static final float lambda = 0.55f;
static final float intensity = 0.6f;
Geometry logoBox;public static void main(String[] args) {
Main app = new Main();
app.setShowSettings(false);
app.start();
}@Override
public void simpleInitApp() {
Vector3f startLocation = new Vector3f(-5f, 6f, -2f);
cam.setLocation(startLocation);
Quaternion startRotation = new Quaternion(0.2f, 0.7f, -0.3f, 0.6f);
cam.setRotation(startRotation);
flyCam.setMoveSpeed(10f);viewPort.setBackgroundColor(ColorRGBA.Gray); DirectionalLight mainLight = new DirectionalLight(); mainLight.setColor(ColorRGBA.White); Vector3f lightDirection = new Vector3f(2f, -9f, -2f).normalize(); mainLight.setDirection(lightDirection); mainLight.setName("main"); rootNode.addLight(mainLight); /* * two geometries: yellow ground and logo box */ Material yellow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); yellow.setBoolean("UseMaterialColors", true); yellow.setColor("Diffuse", ColorRGBA.Yellow); Box groundMesh = new Box(8f, 0.2f, 8f); Geometry ground = new Geometry("ground", groundMesh); ground.setMaterial(yellow); ground.setLocalTranslation(0f, -0.2f, 0f); ground.setShadowMode(RenderQueue.ShadowMode.Receive); rootNode.attachChild(ground); Material logoMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Texture logo = assetManager.loadTexture("Interface/Logo/Monkey.png"); logoMaterial.setTexture("DiffuseMap", logo); Box boxMesh = new Box(0.3f, 0.3f, 0.3f); logoBox = new Geometry("box", boxMesh); logoBox.setLocalTranslation(0f, 0.6f, -3f); logoBox.setMaterial(logoMaterial); logoBox.setShadowMode(RenderQueue.ShadowMode.Cast); rootNode.attachChild(logoBox); /* * Add shadow processors. */ DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, shadowMapSize, nbSplits); dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest); dlsr.setLambda(lambda); dlsr.setLight(mainLight); dlsr.setShadowIntensity(intensity); viewPort.addProcessor(dlsr); DirectionalLightShadowFilter filter = new DirectionalLightShadowFilter(assetManager, shadowMapSize, nbSplits); filter.setEdgeFilteringMode(EdgeFilteringMode.Nearest); filter.setEnabled(true); filter.setLambda(lambda); filter.setLight(mainLight); filter.setShadowIntensity(intensity); FilterPostProcessor postProcessor = new FilterPostProcessor(assetManager); postProcessor.addFilter(filter); viewPort.addProcessor(postProcessor); /* * Press 'N' key to toggle the logo box in or out of the scene. */ inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_N)); inputManager.addListener(this, "toggle");
}
@Override
public void onAction(String actionString, boolean ongoing, float unused) {
if (!ongoing) {
return;
}
if (“toggle”.equals(actionString)) {
if (logoBox.getParent() == null) {
System.out.println("\n ATTACHING logo box\n");
rootNode.attachChild(logoBox);} else { System.out.println("\n DETACHING logo box\n"); rootNode.detachChild(logoBox); } }
}
}
[/java]