Search in sources :

Example 1 with PssmShadowFilter

use of com.jme3.shadow.PssmShadowFilter in project jmonkeyengine by jMonkeyEngine.

the class TestShadowsPerf method simpleInitApp.

@Override
public void simpleInitApp() {
    Logger.getLogger("com.jme3").setLevel(Level.SEVERE);
    flyCam.setMoveSpeed(50);
    flyCam.setEnabled(false);
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    cam.setLocation(new Vector3f(-53.952988f, 27.15874f, -32.875023f));
    cam.setRotation(new Quaternion(0.1564309f, 0.6910534f, -0.15713608f, 0.6879555f));
    //        cam.setLocation(new Vector3f(53.64627f, 130.56f, -11.247704f));
    //        cam.setRotation(new Quaternion(-6.5737107E-4f, 0.76819664f, -0.64021313f, -7.886125E-4f));   
    //// 
    cam.setFrustumFar(500);
    mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    Box b = new Box(800, 1, 700);
    b.scaleTextureCoordinates(new Vector2f(50, 50));
    Geometry ground = new Geometry("ground", b);
    ground.setMaterial(mat);
    rootNode.attachChild(ground);
    ground.setShadowMode(ShadowMode.Receive);
    Sphere sphMesh = new Sphere(32, 32, 1);
    sphMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphMesh.updateGeometry(32, 32, 1, false, false);
    TangentBinormalGenerator.generate(sphMesh);
    sphere = new Geometry("Rock Ball", sphMesh);
    sphere.setLocalTranslation(0, 5, 0);
    sphere.setMaterial(mat);
    sphere.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(sphere);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
    dl.setColor(ColorRGBA.White);
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.7f));
    rootNode.addLight(al);
    //rootNode.setShadowMode(ShadowMode.CastAndReceive);
    createballs();
    final DirectionalLightShadowRenderer pssmRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 4);
    viewPort.addProcessor(pssmRenderer);
    //        
    //        final PssmShadowFilter pssmRenderer = new PssmShadowFilter(assetManager, 1024, 4);
    //        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);        
    //        fpp.addFilter(pssmRenderer);
    //        viewPort.addProcessor(fpp);
    pssmRenderer.setLight(dl);
    pssmRenderer.setLambda(0.55f);
    pssmRenderer.setShadowIntensity(0.55f);
    pssmRenderer.setShadowCompareMode(com.jme3.shadow.CompareMode.Software);
    pssmRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    //pssmRenderer.displayDebug();
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("display") && isPressed) {
                //pssmRenderer.debugFrustrums();
                System.out.println("tetetetet");
            }
            if (name.equals("add") && isPressed) {
                createballs();
            }
        }
    }, "display", "add");
    inputManager.addMapping("display", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("add", new KeyTrigger(KeyInput.KEY_RETURN));
}
Also used : Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ActionListener(com.jme3.input.controls.ActionListener) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) DirectionalLightShadowRenderer(com.jme3.shadow.DirectionalLightShadowRenderer) AmbientLight(com.jme3.light.AmbientLight)

Example 2 with PssmShadowFilter

use of com.jme3.shadow.PssmShadowFilter in project jmonkeyengine by jMonkeyEngine.

the class TestPssmShadow method simpleInitApp.

@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(65.25412f, 44.38738f, 9.087874f));
    cam.setRotation(new Quaternion(0.078139365f, 0.050241485f, -0.003942559f, 0.9956679f));
    flyCam.setMoveSpeed(100);
    loadScene();
    pssmRenderer = new PssmShadowRenderer(assetManager, 1024, 3);
    //pssmRenderer.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    pssmRenderer.setDirection(new Vector3f(-0.5973172f, -0.56583486f, 0.8846725f).normalizeLocal());
    pssmRenderer.setLambda(0.55f);
    pssmRenderer.setShadowIntensity(0.6f);
    pssmRenderer.setCompareMode(CompareMode.Software);
    pssmRenderer.setFilterMode(FilterMode.Dither);
    pssmRenderer.displayFrustum();
    viewPort.addProcessor(pssmRenderer);
    pssmFilter = new PssmShadowFilter(assetManager, 1024, 3);
    //pssmFilter.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    pssmRenderer.setDirection(new Vector3f(-0.5973172f, -0.56583486f, 0.8846725f).normalizeLocal());
    pssmFilter.setLambda(0.55f);
    pssmFilter.setShadowIntensity(0.6f);
    pssmFilter.setCompareMode(CompareMode.Software);
    pssmFilter.setFilterMode(FilterMode.Dither);
    pssmFilter.setEnabled(false);
    //        pssmFilter.setShadowZFadeLength(300);
    //        pssmFilter.setShadowZExtend(500);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //  fpp.setNumSamples(4);
    fpp.addFilter(pssmFilter);
    viewPort.addProcessor(fpp);
    initInputs();
}
Also used : PssmShadowFilter(com.jme3.shadow.PssmShadowFilter) PssmShadowRenderer(com.jme3.shadow.PssmShadowRenderer) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) FilterPostProcessor(com.jme3.post.FilterPostProcessor)

Aggregations

Quaternion (com.jme3.math.Quaternion)2 Vector3f (com.jme3.math.Vector3f)2 ActionListener (com.jme3.input.controls.ActionListener)1 KeyTrigger (com.jme3.input.controls.KeyTrigger)1 AmbientLight (com.jme3.light.AmbientLight)1 DirectionalLight (com.jme3.light.DirectionalLight)1 Vector2f (com.jme3.math.Vector2f)1 FilterPostProcessor (com.jme3.post.FilterPostProcessor)1 Geometry (com.jme3.scene.Geometry)1 Box (com.jme3.scene.shape.Box)1 Sphere (com.jme3.scene.shape.Sphere)1 DirectionalLightShadowRenderer (com.jme3.shadow.DirectionalLightShadowRenderer)1 PssmShadowFilter (com.jme3.shadow.PssmShadowFilter)1 PssmShadowRenderer (com.jme3.shadow.PssmShadowRenderer)1