Search in sources :

Example 1 with DepthOfFieldFilter

use of com.jme3.post.filters.DepthOfFieldFilter in project jmonkeyengine by jMonkeyEngine.

the class TestDepthOfField method simpleInitApp.

@Override
public void simpleInitApp() {
    Node mainScene = new Node("Main Scene");
    rootNode.attachChild(mainScene);
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
    mainScene.addLight(sun);
    DirectionalLight l = new DirectionalLight();
    l.setDirection(Vector3f.UNIT_Y.mult(-1));
    l.setColor(ColorRGBA.White.clone().multLocal(0.3f));
    mainScene.addLight(l);
    flyCam.setMoveSpeed(50);
    cam.setFrustumFar(3000);
    cam.setLocation(new Vector3f(-700, 100, 300));
    cam.setRotation(new Quaternion().fromAngles(new float[] { FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0 }));
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    mainScene.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    //     fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    dofFilter = new DepthOfFieldFilter();
    dofFilter.setFocusDistance(0);
    dofFilter.setFocusRange(50);
    dofFilter.setBlurScale(1.4f);
    fpp.addFilter(dofFilter);
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("toggle")) {
                    dofFilter.setEnabled(!dofFilter.isEnabled());
                }
            }
        }
    }, "toggle");
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("blurScaleUp")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() + 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("blurScaleDown")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() - 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("focusRangeUp")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() + 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusRangeDown")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() - 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusDistanceUp")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() + 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
            if (name.equals("focusDistanceDown")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() - 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
        }
    }, "blurScaleUp", "blurScaleDown", "focusRangeUp", "focusRangeDown", "focusDistanceUp", "focusDistanceDown");
    inputManager.addMapping("toggle", new KeyTrigger(keyInput.KEY_SPACE));
    inputManager.addMapping("blurScaleUp", new KeyTrigger(keyInput.KEY_U));
    inputManager.addMapping("blurScaleDown", new KeyTrigger(keyInput.KEY_J));
    inputManager.addMapping("focusRangeUp", new KeyTrigger(keyInput.KEY_I));
    inputManager.addMapping("focusRangeDown", new KeyTrigger(keyInput.KEY_K));
    inputManager.addMapping("focusDistanceUp", new KeyTrigger(keyInput.KEY_O));
    inputManager.addMapping("focusDistanceDown", new KeyTrigger(keyInput.KEY_L));
}
Also used : Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DepthOfFieldFilter(com.jme3.post.filters.DepthOfFieldFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 2 with DepthOfFieldFilter

use of com.jme3.post.filters.DepthOfFieldFilter in project jmonkeyengine by jMonkeyEngine.

the class TestPostWater method simpleInitApp.

@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);
    Node mainScene = new Node("Main Scene");
    rootNode.attachChild(mainScene);
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(1f));
    mainScene.addLight(sun);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
    mainScene.addLight(al);
    flyCam.setMoveSpeed(50);
    //cam.setLocation(new Vector3f(-700, 100, 300));
    //cam.setRotation(new Quaternion().fromAngleAxis(0.5f, Vector3f.UNIT_Z));
    //        cam.setLocation(new Vector3f(-327.21957f, 61.6459f, 126.884346f));
    //        cam.setRotation(new Quaternion(0.052168474f, 0.9443102f, -0.18395276f, 0.2678024f));
    cam.setLocation(new Vector3f(-370.31592f, 182.04016f, 196.81192f));
    cam.setRotation(new Quaternion(0.015302252f, 0.9304095f, -0.039101653f, 0.3641086f));
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    mainScene.attachChild(sky);
    cam.setFrustumFar(4000);
    //Water Filter
    water = new WaterFilter(rootNode, lightDir);
    water.setWaterColor(new ColorRGBA().setAsSrgb(0.0078f, 0.3176f, 0.5f, 1.0f));
    water.setDeepWaterColor(new ColorRGBA().setAsSrgb(0.0039f, 0.00196f, 0.145f, 1.0f));
    water.setUnderWaterFogDistance(80);
    water.setWaterTransparency(0.12f);
    water.setFoamIntensity(0.4f);
    water.setFoamHardness(0.3f);
    water.setFoamExistence(new Vector3f(0.8f, 8f, 1f));
    water.setReflectionDisplace(50);
    water.setRefractionConstant(0.25f);
    water.setColorExtinction(new Vector3f(30, 50, 70));
    water.setCausticsIntensity(0.4f);
    water.setWaveScale(0.003f);
    water.setMaxAmplitude(2f);
    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
    water.setRefractionStrength(0.2f);
    water.setWaterHeight(initialWaterHeight);
    //Bloom Filter
    BloomFilter bloom = new BloomFilter();
    bloom.setExposurePower(55);
    bloom.setBloomIntensity(1.0f);
    //Light Scattering Filter
    LightScatteringFilter lsf = new LightScatteringFilter(lightDir.mult(-300));
    lsf.setLightDensity(0.5f);
    //Depth of field Filter
    DepthOfFieldFilter dof = new DepthOfFieldFilter();
    dof.setFocusDistance(0);
    dof.setFocusRange(100);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(water);
    fpp.addFilter(bloom);
    fpp.addFilter(dof);
    fpp.addFilter(lsf);
    fpp.addFilter(new FXAAFilter());
    //      fpp.addFilter(new TranslucentBucketFilter());
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    uw = cam.getLocation().y < waterHeight;
    waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
    waves.setLooping(true);
    waves.setReverbEnabled(true);
    if (uw) {
        waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
    } else {
        waves.setDryFilter(aboveWaterAudioFilter);
    }
    audioRenderer.playSource(waves);
    //  
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("foam1")) {
                    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg"));
                }
                if (name.equals("foam2")) {
                    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
                }
                if (name.equals("foam3")) {
                    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam3.jpg"));
                }
                if (name.equals("upRM")) {
                    water.setReflectionMapSize(Math.min(water.getReflectionMapSize() * 2, 4096));
                    System.out.println("Reflection map size : " + water.getReflectionMapSize());
                }
                if (name.equals("downRM")) {
                    water.setReflectionMapSize(Math.max(water.getReflectionMapSize() / 2, 32));
                    System.out.println("Reflection map size : " + water.getReflectionMapSize());
                }
            }
        }
    }, "foam1", "foam2", "foam3", "upRM", "downRM");
    inputManager.addMapping("foam1", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("foam2", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addMapping("foam3", new KeyTrigger(KeyInput.KEY_3));
    inputManager.addMapping("upRM", new KeyTrigger(KeyInput.KEY_PGUP));
    inputManager.addMapping("downRM", new KeyTrigger(KeyInput.KEY_PGDN));
//        createBox();
//        createFire();
}
Also used : FXAAFilter(com.jme3.post.filters.FXAAFilter) Texture2D(com.jme3.texture.Texture2D) LightScatteringFilter(com.jme3.post.filters.LightScatteringFilter) LowPassFilter(com.jme3.audio.LowPassFilter) Quaternion(com.jme3.math.Quaternion) AudioNode(com.jme3.audio.AudioNode) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter) DepthOfFieldFilter(com.jme3.post.filters.DepthOfFieldFilter) ColorRGBA(com.jme3.math.ColorRGBA) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WaterFilter(com.jme3.water.WaterFilter) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) AmbientLight(com.jme3.light.AmbientLight) AudioNode(com.jme3.audio.AudioNode)

Aggregations

ActionListener (com.jme3.input.controls.ActionListener)2 KeyTrigger (com.jme3.input.controls.KeyTrigger)2 DirectionalLight (com.jme3.light.DirectionalLight)2 FilterPostProcessor (com.jme3.post.FilterPostProcessor)2 DepthOfFieldFilter (com.jme3.post.filters.DepthOfFieldFilter)2 Node (com.jme3.scene.Node)2 Spatial (com.jme3.scene.Spatial)2 AudioNode (com.jme3.audio.AudioNode)1 LowPassFilter (com.jme3.audio.LowPassFilter)1 AnalogListener (com.jme3.input.controls.AnalogListener)1 AmbientLight (com.jme3.light.AmbientLight)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Quaternion (com.jme3.math.Quaternion)1 Vector3f (com.jme3.math.Vector3f)1 BloomFilter (com.jme3.post.filters.BloomFilter)1 FXAAFilter (com.jme3.post.filters.FXAAFilter)1 LightScatteringFilter (com.jme3.post.filters.LightScatteringFilter)1 Texture2D (com.jme3.texture.Texture2D)1 WaterFilter (com.jme3.water.WaterFilter)1