use of com.jme3.shadow.DirectionalLightShadowRenderer 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.DirectionalLightShadowRenderer in project jmonkeyengine by jMonkeyEngine.
the class TestTransparentShadow method simpleInitApp.
public void simpleInitApp() {
cam.setLocation(new Vector3f(5.700248f, 6.161693f, 5.1404157f));
cam.setRotation(new Quaternion(-0.09441641f, 0.8993388f, -0.24089815f, -0.35248178f));
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
Quad q = new Quad(20, 20);
q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(10));
TangentBinormalGenerator.generate(q);
Geometry geom = new Geometry("floor", q);
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
geom.setMaterial(mat);
geom.rotate(-FastMath.HALF_PI, 0, 0);
geom.center();
geom.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(geom);
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.7f));
rootNode.addLight(al);
DirectionalLight dl1 = new DirectionalLight();
dl1.setDirection(new Vector3f(0, -1, 0.5f).normalizeLocal());
dl1.setColor(ColorRGBA.White.mult(1.5f));
rootNode.addLight(dl1);
// create the geometry and attach it
Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
tree.setQueueBucket(Bucket.Transparent);
tree.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(tree);
// Uses Texture from jme3-test-data library!
ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
fire.setShadowMode(ShadowMode.Cast);
fire.setMaterial(mat_red);
fire.setImagesX(2);
// 2x2 texture animation
fire.setImagesY(2);
// red
fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
// yellow
fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
fire.setStartSize(0.6f);
fire.setEndSize(0.1f);
fire.setGravity(0, 0, 0);
fire.setLowLife(0.5f);
fire.setHighLife(1.5f);
fire.getParticleInfluencer().setVelocityVariation(0.3f);
fire.setLocalTranslation(5.0f, 0, 1.0f);
fire.setLocalScale(0.3f);
fire.setQueueBucket(Bucket.Translucent);
rootNode.attachChild(fire);
Material mat2 = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
Geometry ball = new Geometry("sphere", new Sphere(16, 16, 0.5f));
ball.setMaterial(mat2);
ball.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(ball);
ball.setLocalTranslation(-1.0f, 1.5f, 1.0f);
final DirectionalLightShadowRenderer dlsRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 1);
dlsRenderer.setLight(dl1);
dlsRenderer.setLambda(0.55f);
dlsRenderer.setShadowIntensity(0.8f);
dlsRenderer.setShadowCompareMode(CompareMode.Software);
dlsRenderer.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
dlsRenderer.displayDebug();
viewPort.addProcessor(dlsRenderer);
inputManager.addMapping("stabilize", new KeyTrigger(KeyInput.KEY_B));
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("stabilize") && isPressed) {
dlsRenderer.setEnabledStabilization(!dlsRenderer.isEnabledStabilization());
}
}
}, "stabilize");
}
use of com.jme3.shadow.DirectionalLightShadowRenderer in project jmonkeyengine by jMonkeyEngine.
the class TestSkeletonControlRefresh method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.White);
flyCam.setMoveSpeed(10f);
cam.setLocation(new Vector3f(3.8664846f, 6.2704787f, 9.664585f));
cam.setRotation(new Quaternion(-0.054774776f, 0.94064945f, -0.27974048f, -0.18418397f));
makeHudText();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey k = new TextureKey("Models/Oto/Oto.jpg", false);
m.setTexture("ColorMap", assetManager.loadTexture(k));
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
//setting a different material
model.setMaterial(m.clone());
model.setLocalScale(0.1f);
model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
control = model.getControl(AnimControl.class);
channel = control.createChannel();
channel.setAnim(animNames[(i + j) % 4]);
channel.setLoopMode(LoopMode.DontLoop);
SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
//This is a workaround the issue. this call will make the SkeletonControl gather the targets again.
//skeletonControl.setSpatial(model);
skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
skControls.add(skeletonControl);
rootNode.attachChild(model);
}
}
rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
setupFloor();
inputManager.addListener(this, "toggleHWS");
inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
// DirectionalLightShadowRenderer pssm = new DirectionalLightShadowRenderer(assetManager, 1024, 2);
// pssm.setLight(dl);
// viewPort.addProcessor(pssm);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
DirectionalLightShadowFilter sf = new DirectionalLightShadowFilter(assetManager, 1024, 2);
sf.setLight(dl);
fpp.addFilter(sf);
fpp.addFilter(new SSAOFilter());
viewPort.addProcessor(fpp);
}
Aggregations