|
|
@ -40,12 +40,14 @@ import com.jme3.input.controls.KeyTrigger; |
|
|
|
import com.jme3.light.AmbientLight; |
|
|
|
import com.jme3.light.AmbientLight; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
|
import com.jme3.material.Material; |
|
|
|
import com.jme3.material.Material; |
|
|
|
|
|
|
|
import com.jme3.material.RenderState; |
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
import com.jme3.math.FastMath; |
|
|
|
import com.jme3.math.FastMath; |
|
|
|
import com.jme3.math.Quaternion; |
|
|
|
import com.jme3.math.Quaternion; |
|
|
|
import com.jme3.math.Vector2f; |
|
|
|
import com.jme3.math.Vector2f; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.post.FilterPostProcessor; |
|
|
|
import com.jme3.post.FilterPostProcessor; |
|
|
|
|
|
|
|
import com.jme3.post.ssao.SSAOFilter; |
|
|
|
import com.jme3.renderer.queue.RenderQueue.ShadowMode; |
|
|
|
import com.jme3.renderer.queue.RenderQueue.ShadowMode; |
|
|
|
import com.jme3.scene.Geometry; |
|
|
|
import com.jme3.scene.Geometry; |
|
|
|
import com.jme3.scene.Spatial; |
|
|
|
import com.jme3.scene.Spatial; |
|
|
@ -69,6 +71,7 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
private Geometry ground; |
|
|
|
private Geometry ground; |
|
|
|
private Material matGroundU; |
|
|
|
private Material matGroundU; |
|
|
|
private Material matGroundL; |
|
|
|
private Material matGroundL; |
|
|
|
|
|
|
|
private AmbientLight al; |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
TestDirectionalLightShadow app = new TestDirectionalLightShadow(); |
|
|
|
TestDirectionalLightShadow app = new TestDirectionalLightShadow(); |
|
|
@ -99,7 +102,7 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m"); |
|
|
|
mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m"); |
|
|
|
mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); |
|
|
|
mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); |
|
|
|
mat[1].setBoolean("UseMaterialColors", true); |
|
|
|
mat[1].setBoolean("UseMaterialColors", true); |
|
|
|
mat[1].setColor("Ambient", ColorRGBA.White.mult(0.5f)); |
|
|
|
mat[1].setColor("Ambient", ColorRGBA.White); |
|
|
|
mat[1].setColor("Diffuse", ColorRGBA.White.clone()); |
|
|
|
mat[1].setColor("Diffuse", ColorRGBA.White.clone()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -110,9 +113,14 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
TangentBinormalGenerator.generate(obj[1]); |
|
|
|
TangentBinormalGenerator.generate(obj[1]); |
|
|
|
TangentBinormalGenerator.generate(obj[0]); |
|
|
|
TangentBinormalGenerator.generate(obj[0]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spatial t = obj[0].clone(false); |
|
|
|
|
|
|
|
t.setLocalScale(10f); |
|
|
|
|
|
|
|
t.setMaterial(mat[1]); |
|
|
|
|
|
|
|
rootNode.attachChild(t); |
|
|
|
|
|
|
|
t.setLocalTranslation(0, 25, 0); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 60; i++) { |
|
|
|
for (int i = 0; i < 60; i++) { |
|
|
|
Spatial t = obj[FastMath.nextRandomInt(0, obj.length - 1)].clone(false); |
|
|
|
t = obj[FastMath.nextRandomInt(0, obj.length - 1)].clone(false); |
|
|
|
t.setLocalScale(FastMath.nextRandomFloat() * 10f); |
|
|
|
t.setLocalScale(FastMath.nextRandomFloat() * 10f); |
|
|
|
t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]); |
|
|
|
t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]); |
|
|
|
rootNode.attachChild(t); |
|
|
|
rootNode.attachChild(t); |
|
|
@ -142,8 +150,8 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
rootNode.addLight(l); |
|
|
|
rootNode.addLight(l); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AmbientLight al = new AmbientLight(); |
|
|
|
al = new AmbientLight(); |
|
|
|
al.setColor(ColorRGBA.White.mult(0.5f)); |
|
|
|
al.setColor(ColorRGBA.White.mult(0.02f)); |
|
|
|
rootNode.addLight(al); |
|
|
|
rootNode.addLight(al); |
|
|
|
|
|
|
|
|
|
|
|
Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false); |
|
|
|
Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false); |
|
|
@ -156,8 +164,11 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void simpleInitApp() { |
|
|
|
public void simpleInitApp() { |
|
|
|
// put the camera in a bad position
|
|
|
|
// put the camera in a bad position
|
|
|
|
cam.setLocation(new Vector3f(65.25412f, 44.38738f, 9.087874f)); |
|
|
|
// cam.setLocation(new Vector3f(65.25412f, 44.38738f, 9.087874f));
|
|
|
|
cam.setRotation(new Quaternion(0.078139365f, 0.050241485f, -0.003942559f, 0.9956679f)); |
|
|
|
// cam.setRotation(new Quaternion(0.078139365f, 0.050241485f, -0.003942559f, 0.9956679f));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cam.setLocation(new Vector3f(3.3720117f, 42.838284f, -83.43792f)); |
|
|
|
|
|
|
|
cam.setRotation(new Quaternion(0.13833192f, -0.08969371f, 0.012581267f, 0.9862358f)); |
|
|
|
|
|
|
|
|
|
|
|
flyCam.setMoveSpeed(100); |
|
|
|
flyCam.setMoveSpeed(100); |
|
|
|
|
|
|
|
|
|
|
@ -166,7 +177,7 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3); |
|
|
|
dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3); |
|
|
|
dlsr.setLight(l); |
|
|
|
dlsr.setLight(l); |
|
|
|
dlsr.setLambda(0.55f); |
|
|
|
dlsr.setLambda(0.55f); |
|
|
|
dlsr.setShadowIntensity(0.6f); |
|
|
|
dlsr.setShadowIntensity(0.8f); |
|
|
|
dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest); |
|
|
|
dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest); |
|
|
|
dlsr.displayDebug(); |
|
|
|
dlsr.displayDebug(); |
|
|
|
viewPort.addProcessor(dlsr); |
|
|
|
viewPort.addProcessor(dlsr); |
|
|
@ -174,7 +185,7 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 3); |
|
|
|
dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 3); |
|
|
|
dlsf.setLight(l); |
|
|
|
dlsf.setLight(l); |
|
|
|
dlsf.setLambda(0.55f); |
|
|
|
dlsf.setLambda(0.55f); |
|
|
|
dlsf.setShadowIntensity(0.6f); |
|
|
|
dlsf.setShadowIntensity(0.8f); |
|
|
|
dlsf.setEdgeFilteringMode(EdgeFilteringMode.Nearest); |
|
|
|
dlsf.setEdgeFilteringMode(EdgeFilteringMode.Nearest); |
|
|
|
dlsf.setEnabled(false); |
|
|
|
dlsf.setEnabled(false); |
|
|
|
|
|
|
|
|
|
|
@ -205,10 +216,11 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
inputManager.addMapping("fwd", new KeyTrigger(KeyInput.KEY_PGUP)); |
|
|
|
inputManager.addMapping("fwd", new KeyTrigger(KeyInput.KEY_PGUP)); |
|
|
|
inputManager.addMapping("back", new KeyTrigger(KeyInput.KEY_PGDN)); |
|
|
|
inputManager.addMapping("back", new KeyTrigger(KeyInput.KEY_PGDN)); |
|
|
|
inputManager.addMapping("pp", new KeyTrigger(KeyInput.KEY_P)); |
|
|
|
inputManager.addMapping("pp", new KeyTrigger(KeyInput.KEY_P)); |
|
|
|
|
|
|
|
inputManager.addMapping("backShadows", new KeyTrigger(KeyInput.KEY_B)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputManager.addListener(this, "lambdaUp", "lambdaDown", "ThicknessUp", "ThicknessDown", |
|
|
|
inputManager.addListener(this, "lambdaUp", "lambdaDown", "ThicknessUp", "ThicknessDown", |
|
|
|
"switchGroundMat", "debug", "up", "down", "right", "left", "fwd", "back", "pp", "stabilize", "distance"); |
|
|
|
"switchGroundMat", "debug", "up", "down", "right", "left", "fwd", "back", "pp", "stabilize", "distance", "ShadowUp", "ShadowDown", "backShadows"); |
|
|
|
|
|
|
|
|
|
|
|
ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, dlsr, dlsf, guiNode, inputManager, viewPort); |
|
|
|
ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, dlsr, dlsf, guiNode, inputManager, viewPort); |
|
|
|
|
|
|
|
|
|
|
@ -255,12 +267,19 @@ public class TestDirectionalLightShadow extends SimpleApplication implements Act |
|
|
|
dlsf.setLambda(dlsr.getLambda() - 0.01f); |
|
|
|
dlsf.setLambda(dlsr.getLambda() - 0.01f); |
|
|
|
System.out.println("Lambda : " + dlsr.getLambda()); |
|
|
|
System.out.println("Lambda : " + dlsr.getLambda()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ((name.equals("ShadowUp") || name.equals("ShadowDown")) && keyPressed) { |
|
|
|
|
|
|
|
al.setColor(ColorRGBA.White.mult((1 - dlsr.getShadowIntensity()) * 0.2f)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (name.equals("debug") && keyPressed) { |
|
|
|
if (name.equals("debug") && keyPressed) { |
|
|
|
dlsr.displayFrustum(); |
|
|
|
dlsr.displayFrustum(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name.equals("backShadows") && keyPressed) { |
|
|
|
|
|
|
|
dlsr.setRenderBackFacesShadows(!dlsr.isRenderBackFacesShadows()); |
|
|
|
|
|
|
|
dlsf.setRenderBackFacesShadows(!dlsf.isRenderBackFacesShadows()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (name.equals("stabilize") && keyPressed) { |
|
|
|
if (name.equals("stabilize") && keyPressed) { |
|
|
|
dlsr.setEnabledStabilization(!dlsr.isEnabledStabilization()); |
|
|
|
dlsr.setEnabledStabilization(!dlsr.isEnabledStabilization()); |
|
|
|
dlsf.setEnabledStabilization(!dlsf.isEnabledStabilization()); |
|
|
|
dlsf.setEnabledStabilization(!dlsf.isEnabledStabilization()); |
|
|
|