Search in sources :

Example 6 with SSAOFilter

use of com.jme3.post.ssao.SSAOFilter in project TeachingInSimulation by ScOrPiOzzy.

the class JmeApplication method simpleInitApp.

@Override
public void simpleInitApp() {
    super.simpleInitApp();
    stateManager.attach(new MouseEventState());
    stateManager.detach(stateManager.getState(FlyCamAppState.class));
    renderer.setMainFrameBufferSrgb(true);
    // String assetPath = SpringUtil.getBean(HTTPUtils.class).getFullPath("assets/");
    // LOG.debug("注册资源路径:{}", assetPath); // http://192.168.x.x:port/***/assests/
    // //		注册资源路径
    // assetManager.registerLocator(assetPath, UrlLocator.class);
    assetManager.registerLocator("assets", FileLocator.class);
    cam.setFrustumPerspective(45, (float) cam.getWidth() / cam.getHeight(), 0.01f, 100f);
// //		创建天空盒
// //		Spatial sky = SkyFactory.createSky(assetManager, "Model/Sky/noon_grass_2k.hdr", SkyFactory.EnvMapType.EquirectMap);
// Spatial sky = SkyFactory.createSky(assetManager, "Model/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
// rootNode.attachChild(sky);
// 
// 滤镜
// fpp.addFilter(new FXAAFilter());
// postProcessor.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(4.0f)));
// fpp.addFilter(new SSAOFilter(0.5f, 3, 0.2f, 0.2f));
}
Also used : MouseEventState(com.cas.sim.tis.app.event.MouseEventState) FlyCamAppState(com.jme3.app.FlyCamAppState)

Example 7 with SSAOFilter

use of com.jme3.post.ssao.SSAOFilter in project TeachingInSimulation by ScOrPiOzzy.

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(256, 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) {
// //                        guiNode.attachChild(tex);
// //                    } else {
// //                        tex.removeFromParent();
// //                    }
// //                }
// 
// if (name.equals("rup") && isPressed) {
// roughness = FastMath.clamp(roughness + 0.1f, 0.0f, 1.0f);
// pbrMat.setFloat("Roughness", roughness);
// }
// if (name.equals("rdown") && isPressed) {
// roughness = FastMath.clamp(roughness - 0.1f, 0.0f, 1.0f);
// pbrMat.setFloat("Roughness", roughness);
// }
// 
// 
// 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", "rup", "rdown");
// 
// 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));
// inputManager.addMapping("rup", new KeyTrigger(KeyInput.KEY_T));
// inputManager.addMapping("rdown", new KeyTrigger(KeyInput.KEY_G));
// MaterialDebugAppState debug = new MaterialDebugAppState();
// debug.registerBinding("Common/MatDefs/Light/PBRLighting.frag", rootNode);
// debug.registerBinding("Common/ShaderLib/PBR.glsllib", rootNode);
// getStateManager().attach(debug);
}
Also used : ToneMapFilter(com.jme3.post.filters.ToneMapFilter) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) Node(com.jme3.scene.Node) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor)

Example 8 with SSAOFilter

use of com.jme3.post.ssao.SSAOFilter 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 9 with SSAOFilter

use of com.jme3.post.ssao.SSAOFilter in project jmonkeyengine by jMonkeyEngine.

the class TestSSAO method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(68.45442f, 8.235511f, 7.9676695f));
    cam.setRotation(new Quaternion(0.046916496f, -0.69500375f, 0.045538206f, 0.7160271f));
    flyCam.setMoveSpeed(50);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Texture diff = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
    diff.setWrap(Texture.WrapMode.Repeat);
    Texture norm = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall_normal.jpg");
    norm.setWrap(Texture.WrapMode.Repeat);
    mat.setTexture("DiffuseMap", diff);
    mat.setTexture("NormalMap", norm);
    mat.setFloat("Shininess", 2.0f);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(1.8f, 1.8f, 1.8f, 1.0f));
    rootNode.addLight(al);
    model = (Geometry) assetManager.loadModel("Models/Sponza/Sponza.j3o");
    model.getMesh().scaleTextureCoordinates(new Vector2f(2, 2));
    model.setMaterial(mat);
    rootNode.attachChild(model);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    SSAOFilter ssaoFilter = new SSAOFilter(2.9299974f, 32.920483f, 5.8100376f, 0.091000035f);
    ;
    ssaoFilter.setApproximateNormals(true);
    fpp.addFilter(ssaoFilter);
    SSAOUI ui = new SSAOUI(inputManager, ssaoFilter);
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) Texture(com.jme3.texture.Texture) AmbientLight(com.jme3.light.AmbientLight)

Example 10 with SSAOFilter

use of com.jme3.post.ssao.SSAOFilter in project jmonkeyengine by jMonkeyEngine.

the class TestSSAO2 method simpleInitApp.

@Override
public void simpleInitApp() {
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    flyCam.setDragToRotate(true);
    setPauseOnLostFocus(false);
    getStateManager().attach(new DetailedProfilerState());
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 16f);
    //mat.setBoolean("VertexLighting", true);
    Geometry floor = new Geometry("floor", new Box(1000, 0.1f, 1000));
    floor.setMaterial(mat);
    rootNode.attachChild(floor);
    Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
    Geometry teapot = (Geometry) teapotNode.getChild(0);
    teapot.setMaterial(mat);
    //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    for (int f = 10; f > 3; f--) {
        for (int y = -f; y < f; y++) {
            for (int x = -f; x < f; x++) {
                Geometry clonePot = teapot.clone();
                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 10 - f, y * .5f);
                clonePot.setLocalScale(.15f);
                rootNode.attachChild(clonePot);
            }
        }
    }
    cam.setLocation(new Vector3f(10.247649f, 8.275992f, 10.405156f));
    cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    SSAOFilter ssaoFilter = new SSAOFilter(2.9299974f, 25f, 5.8100376f, 0.091000035f);
    int numSamples = context.getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    //ssaoFilter.setApproximateNormals(true);
    fpp.addFilter(ssaoFilter);
    SSAOUI ui = new SSAOUI(inputManager, ssaoFilter);
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) DetailedProfilerState(com.jme3.app.DetailedProfilerState) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor)

Aggregations

FilterPostProcessor (com.jme3.post.FilterPostProcessor)14 SSAOFilter (com.jme3.post.ssao.SSAOFilter)12 Vector3f (com.jme3.math.Vector3f)10 KeyTrigger (com.jme3.input.controls.KeyTrigger)7 DirectionalLight (com.jme3.light.DirectionalLight)7 Material (com.jme3.material.Material)6 Quaternion (com.jme3.math.Quaternion)6 Spatial (com.jme3.scene.Spatial)5 ActionListener (com.jme3.input.controls.ActionListener)4 AmbientLight (com.jme3.light.AmbientLight)4 ColorRGBA (com.jme3.math.ColorRGBA)4 EnvironmentCamera (com.jme3.environment.EnvironmentCamera)3 BloomFilter (com.jme3.post.filters.BloomFilter)3 FXAAFilter (com.jme3.post.filters.FXAAFilter)3 ToneMapFilter (com.jme3.post.filters.ToneMapFilter)3 Geometry (com.jme3.scene.Geometry)3 Node (com.jme3.scene.Node)3 DirectionalLightShadowFilter (com.jme3.shadow.DirectionalLightShadowFilter)3 ChaseCamera (com.jme3.input.ChaseCamera)2 PointLight (com.jme3.light.PointLight)2