Search in sources :

Example 1 with FXAAFilter

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

the class TestPbrEnv method simpleInitApp.

@Override
public void simpleInitApp() {
    assetManager.registerLoader(KTXLoader.class, "ktx");
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-52.433647f, 68.69636f, -118.60924f));
    cam.setRotation(new Quaternion(0.10294232f, 0.25269797f, -0.027049713f, 0.96167296f));
    flyCam.setMoveSpeed(100);
    loadScene();
    dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 4);
    dlsr.setLight(l);
    //dlsr.setLambda(0.55f);
    dlsr.setShadowIntensity(0.5f);
    dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    //dlsr.displayDebug();
    //       viewPort.addProcessor(dlsr);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(6.0f)));
    SSAOFilter ssao = new SSAOFilter();
    ssao.setIntensity(5);
    fpp.addFilter(ssao);
    BloomFilter bloomFilter = new BloomFilter();
    fpp.addFilter(bloomFilter);
    fpp.addFilter(new FXAAFilter());
    //viewPort.addProcessor(fpp);
    initInputs();
    //        envManager = new EnvironmentManager();
    //        getStateManager().attach(envManager);
    //        
    envCam = new EnvironmentCamera();
    getStateManager().attach(envCam);
    debugState = new LightsDebugState();
    debugState.setProbeScale(5);
    getStateManager().attach(debugState);
    camGeom = new Geometry("camGeom", new Sphere(16, 16, 2));
    //        Material m = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
    //        m.setColor("Color", ColorRGBA.Green);
    Material m = assetManager.loadMaterial("jme3test/light/pbr/pbrMat3.j3m");
    camGeom.setMaterial(m);
    camGeom.setLocalTranslation(0, 20, 0);
    camGeom.setLocalScale(5);
    rootNode.attachChild(camGeom);
    //     envManager.setScene(rootNode);
    //        MaterialDebugAppState debug = new MaterialDebugAppState();
    //        debug.registerBinding("MatDefs/PBRLighting.frag", rootNode);
    //        getStateManager().attach(debug);
    flyCam.setDragToRotate(true);
    setPauseOnLostFocus(false);
// cam.lookAt(camGeom.getWorldTranslation(), Vector3f.UNIT_Y);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) FXAAFilter(com.jme3.post.filters.FXAAFilter) Quaternion(com.jme3.math.Quaternion) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) LightsDebugState(com.jme3.environment.util.LightsDebugState) BloomFilter(com.jme3.post.filters.BloomFilter) ToneMapFilter(com.jme3.post.filters.ToneMapFilter) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) BoundingSphere(com.jme3.bounding.BoundingSphere) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) Vector3f(com.jme3.math.Vector3f) DirectionalLightShadowRenderer(com.jme3.shadow.DirectionalLightShadowRenderer)

Example 2 with FXAAFilter

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

the class TestJaime method setupLights.

public void setupLights() {
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1));
    rootNode.addLight(al);
    SpotLight sl = new SpotLight();
    sl.setColor(ColorRGBA.White.mult(1.0f));
    sl.setPosition(new Vector3f(1.2074411f, 10.6868908f, 4.1489987f));
    sl.setDirection(sl.getPosition().mult(-1));
    sl.setSpotOuterAngle(0.1f);
    sl.setSpotInnerAngle(0.004f);
    rootNode.addLight(sl);
    //pointlight to fake indirect light coming from the ground
    PointLight pl = new PointLight();
    pl.setColor(ColorRGBA.White.mult(1.5f));
    pl.setPosition(new Vector3f(0, 0, 1));
    pl.setRadius(2);
    rootNode.addLight(pl);
    SpotLightShadowRenderer shadows = new SpotLightShadowRenderer(assetManager, 1024);
    shadows.setLight(sl);
    shadows.setShadowIntensity(0.3f);
    shadows.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
    viewPort.addProcessor(shadows);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    SSAOFilter filter = new SSAOFilter(0.10997847f, 0.440001f, 0.39999998f, -0.008000026f);
    ;
    fpp.addFilter(filter);
    fpp.addFilter(new FXAAFilter());
    fpp.addFilter(new FXAAFilter());
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) FXAAFilter(com.jme3.post.filters.FXAAFilter) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) FilterPostProcessor(com.jme3.post.FilterPostProcessor) PointLight(com.jme3.light.PointLight) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) AmbientLight(com.jme3.light.AmbientLight)

Example 3 with FXAAFilter

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

the class TestPBRLighting method simpleInitApp.

@Override
public void simpleInitApp() {
    assetManager.registerLoader(KTXLoader.class, "ktx");
    viewPort.setBackgroundColor(ColorRGBA.White);
    modelNode = (Node) new Node("modelNode");
    model = (Geometry) assetManager.loadModel("Models/Tank/tank.j3o");
    MikktspaceTangentGenerator.generate(model);
    modelNode.attachChild(model);
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    dl.setColor(ColorRGBA.White);
    rootNode.attachChild(modelNode);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //        fpp.addFilter(new FXAAFilter());
    fpp.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(4.0f)));
    //        fpp.addFilter(new SSAOFilter(0.5f, 3, 0.2f, 0.2f));
    viewPort.addProcessor(fpp);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Sky_Cloudy.hdr", SkyFactory.EnvMapType.EquirectMap);
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/road.hdr", SkyFactory.EnvMapType.EquirectMap);
    rootNode.attachChild(sky);
    pbrMat = assetManager.loadMaterial("Models/Tank/tank.j3m");
    model.setMaterial(pbrMat);
    final EnvironmentCamera envCam = new EnvironmentCamera(128, new Vector3f(0, 3f, 0));
    stateManager.attach(envCam);
    //        EnvironmentManager envManager = new EnvironmentManager();
    //        stateManager.attach(envManager);
    //       envManager.setScene(rootNode);
    LightsDebugState debugState = new LightsDebugState();
    stateManager.attach(debugState);
    ChaseCamera chaser = new ChaseCamera(cam, modelNode, inputManager);
    chaser.setDragToRotate(true);
    chaser.setMinVerticalRotation(-FastMath.HALF_PI);
    chaser.setMaxDistance(1000);
    chaser.setSmoothMotion(true);
    chaser.setRotationSensitivity(10);
    chaser.setZoomSensitivity(5);
    flyCam.setEnabled(false);
    //flyCam.setMoveSpeed(100);
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("debug") && isPressed) {
                if (tex == null) {
                    return;
                }
                if (tex.getParent() == null && tex2.getParent() == null) {
                    guiNode.attachChild(tex);
                } else if (tex2.getParent() == null) {
                    tex.removeFromParent();
                    guiNode.attachChild(tex2);
                } else {
                    tex2.removeFromParent();
                }
            }
            if (name.equals("up") && isPressed) {
                model.move(0, tpf * 100f, 0);
            }
            if (name.equals("down") && isPressed) {
                model.move(0, -tpf * 100f, 0);
            }
            if (name.equals("left") && isPressed) {
                model.move(0, 0, tpf * 100f);
            }
            if (name.equals("right") && isPressed) {
                model.move(0, 0, -tpf * 100f);
            }
            if (name.equals("light") && isPressed) {
                dl.setDirection(cam.getDirection().normalize());
            }
        }
    }, "toggle", "light", "up", "down", "left", "right", "debug");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("light", new KeyTrigger(KeyInput.KEY_F));
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("debug", new KeyTrigger(KeyInput.KEY_D));
    MaterialDebugAppState debug = new MaterialDebugAppState();
    debug.registerBinding("Common/MatDefs/Light/PBRLighting.frag", rootNode);
    getStateManager().attach(debug);
}
Also used : MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor) ToneMapFilter(com.jme3.post.filters.ToneMapFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Example 4 with FXAAFilter

use of com.jme3.post.filters.FXAAFilter 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

Vector3f (com.jme3.math.Vector3f)4 FilterPostProcessor (com.jme3.post.FilterPostProcessor)4 FXAAFilter (com.jme3.post.filters.FXAAFilter)3 EnvironmentCamera (com.jme3.environment.EnvironmentCamera)2 ActionListener (com.jme3.input.controls.ActionListener)2 KeyTrigger (com.jme3.input.controls.KeyTrigger)2 AmbientLight (com.jme3.light.AmbientLight)2 DirectionalLight (com.jme3.light.DirectionalLight)2 ColorRGBA (com.jme3.math.ColorRGBA)2 Quaternion (com.jme3.math.Quaternion)2 BloomFilter (com.jme3.post.filters.BloomFilter)2 ToneMapFilter (com.jme3.post.filters.ToneMapFilter)2 SSAOFilter (com.jme3.post.ssao.SSAOFilter)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 BoundingSphere (com.jme3.bounding.BoundingSphere)1 LightsDebugState (com.jme3.environment.util.LightsDebugState)1 ChaseCamera (com.jme3.input.ChaseCamera)1