use of com.jme3.shadow.SpotLightShadowFilter in project jmonkeyengine by jMonkeyEngine.
the class TestPointDirectionalAndSpotLightShadows method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10);
cam.setLocation(new Vector3f(0.040581334f, 1.7745866f, 6.155161f));
cam.setRotation(new Quaternion(4.3868728E-5f, 0.9999293f, -0.011230096f, 0.0039059948f));
Node scene = (Node) assetManager.loadModel("Models/Test/CornellBox.j3o");
scene.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
rootNode.attachChild(scene);
rootNode.getChild("Cube").setShadowMode(RenderQueue.ShadowMode.Receive);
lightNode = (Node) rootNode.getChild("Lamp");
Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
//Geometry lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
lightMdl.setShadowMode(RenderQueue.ShadowMode.Off);
lightNode.attachChild(lightMdl);
//lightMdl.setLocalTranslation(lightNode.getLocalTranslation());
Geometry box = new Geometry("box", new Box(0.2f, 0.2f, 0.2f));
//Geometry lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
box.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
rootNode.attachChild(box);
box.setLocalTranslation(-1f, 0.5f, -2);
((PointLight) scene.getLocalLightList().get(0)).setColor(ColorRGBA.Red);
plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
plsr.setLight((PointLight) scene.getLocalLightList().get(0));
plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
plsf.setLight((PointLight) scene.getLocalLightList().get(0));
plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
plsf.setEnabled(useFilter);
//DIRECTIONAL LIGHT
DirectionalLight directionalLight = new DirectionalLight();
rootNode.addLight(directionalLight);
directionalLight.setColor(ColorRGBA.Blue);
directionalLight.setDirection(new Vector3f(-1f, -.2f, 0f));
dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE * 2, 4);
dlsr.setLight(directionalLight);
dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE * 2, 4);
dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
dlsf.setLight(directionalLight);
dlsf.setEnabled(useFilter);
//SPOT LIGHT
spotLight = new SpotLight();
spotLight.setDirection(new Vector3f(1f, -1f, 0f));
spotLight.setPosition(new Vector3f(-1f, 3f, 0f));
spotLight.setSpotOuterAngle(0.5f);
spotLight.setColor(ColorRGBA.Green);
Sphere sphere = new Sphere(8, 8, .1f);
Geometry sphereGeometry = new Geometry("Sphere", sphere);
sphereGeometry.setLocalTranslation(-1f, 3f, 0f);
sphereGeometry.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"));
rootNode.attachChild(sphereGeometry);
rootNode.addLight(spotLight);
slsr = new SpotLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
slsr.setLight(spotLight);
slsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
slsf = new SpotLightShadowFilter(assetManager, SHADOWMAP_SIZE);
slsf.setLight(spotLight);
slsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
slsf.setEnabled(useFilter);
if (!useFilter)
viewPort.addProcessor(slsr);
if (!useFilter)
viewPort.addProcessor(plsr);
if (!useFilter)
viewPort.addProcessor(dlsr);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(plsf);
fpp.addFilter(dlsf);
fpp.addFilter(slsf);
viewPort.addProcessor(fpp);
ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
ShadowTestUIManager uiManPls = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
ShadowTestUIManager uiManDls = new ShadowTestUIManager(assetManager, dlsr, dlsf, guiNode, inputManager, viewPort);
ShadowTestUIManager uiManSls = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
}
use of com.jme3.shadow.SpotLightShadowFilter in project jmonkeyengine by jMonkeyEngine.
the class TestSpotLightShadows method setupLighting.
public void setupLighting() {
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.02f));
rootNode.addLight(al);
rootNode.setShadowMode(ShadowMode.CastAndReceive);
spot = new SpotLight();
spot.setSpotRange(1000);
spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
spot.setColor(ColorRGBA.White.mult(2));
rootNode.addLight(spot);
// PointLight pl=new PointLight();
// pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
// pl.setRadius(1000);
// pl.setColor(ColorRGBA.White.mult(2));
// rootNode.addLight(pl);
lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
lightMdl.setLocalScale(5);
rootNode.attachChild(lightMdl);
// DirectionalLight dl = new DirectionalLight();
// dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
// dl.setColor(ColorRGBA.White.mult(0.7f));
// rootNode.addLight(dl);
final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
slsr.setLight(spot);
slsr.setShadowIntensity(0.5f);
slsr.setShadowZExtend(100);
slsr.setShadowZFadeLength(5);
slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
viewPort.addProcessor(slsr);
SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
slsf.setLight(spot);
slsf.setShadowIntensity(0.5f);
slsf.setShadowZExtend(100);
slsf.setShadowZFadeLength(5);
slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
slsf.setEnabled(false);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(slsf);
viewPort.addProcessor(fpp);
ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("stop") && isPressed) {
stop = !stop;
// slsr.displayFrustum();
System.out.println("pos : " + spot.getPosition());
System.out.println("dir : " + spot.getDirection());
}
}
}, "stop");
inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_1));
flyCam.setDragToRotate(true);
}
Aggregations