Search in sources :

Example 1 with EnvironmentCamera

use of com.jme3.environment.EnvironmentCamera 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 EnvironmentCamera

use of com.jme3.environment.EnvironmentCamera 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 3 with EnvironmentCamera

use of com.jme3.environment.EnvironmentCamera in project jmonkeyengine by jMonkeyEngine.

the class RefEnv method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(-2.3324413f, 2.9567573f, 4.6054406f));
    cam.setRotation(new Quaternion(0.06310794f, 0.9321281f, -0.29613864f, 0.1986369f));
    Spatial sc = assetManager.loadModel("Scenes/PBR/spheres.j3o");
    rootNode.attachChild(sc);
    rootNode.getChild("Scene").setCullHint(Spatial.CullHint.Always);
    ref = new Node("reference pictures");
    refDE = new Picture("refDE");
    refDE.setHeight(cam.getHeight());
    refDE.setWidth(cam.getWidth());
    refDE.setImage(assetManager, "jme3test/light/pbr/spheresRefDE.png", false);
    refM = new Picture("refM");
    refM.setImage(assetManager, "jme3test/light/pbr/spheresRefM.png", false);
    refM.setHeight(cam.getHeight());
    refM.setWidth(cam.getWidth());
    ref.attachChild(refDE);
    stateManager.attach(new EnvironmentCamera());
    inputManager.addMapping("tex", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("switch", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("ref", new KeyTrigger(KeyInput.KEY_R));
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("tex") && isPressed) {
                if (tex == null) {
                    return;
                }
                if (tex.getParent() == null) {
                    guiNode.attachChild(tex);
                } else {
                    tex.removeFromParent();
                }
            }
            if (name.equals("switch") && isPressed) {
                switchMat(rootNode.getChild("Scene"));
            }
            if (name.equals("ref") && isPressed) {
                if (ref.getParent() == null) {
                    guiNode.attachChild(ref);
                } else {
                    ref.removeFromParent();
                }
            }
        }
    }, "tex", "switch", "ref");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) Picture(com.jme3.ui.Picture) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 4 with EnvironmentCamera

use of com.jme3.environment.EnvironmentCamera 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 5 with EnvironmentCamera

use of com.jme3.environment.EnvironmentCamera in project jmonkeyengine by jMonkeyEngine.

the class LightProbeFactory method makeProbe.

/**
     * Creates a LightProbe with the giver EnvironmentCamera in the given scene.
     * 
     * Note that this is an assynchronous process that will run on multiple threads.
     * The process is thread safe.
     * The created lightProbe will only be marked as ready when the rendering process is done.
     *      
     * The JobProgressListener will be notified of the progress of the generation. 
     * Note that you can also use a {@link JobProgressAdapter}. 
     * 
     * @see LightProbe
     * @see EnvironmentCamera
     * @see JobProgressListener
     
     * @param envCam the EnvironmentCamera
     * @param scene the Scene
     * @param listener the listener of the genration progress.
     * @return the created LightProbe
     */
public static LightProbe makeProbe(final EnvironmentCamera envCam, Spatial scene, final JobProgressListener<LightProbe> listener) {
    final LightProbe probe = new LightProbe();
    probe.setPosition(envCam.getPosition());
    probe.setIrradianceMap(EnvMapUtils.createIrradianceMap(envCam.getSize(), envCam.getImageFormat()));
    probe.setPrefilteredMap(EnvMapUtils.createPrefilteredEnvMap(envCam.getSize(), envCam.getImageFormat()));
    envCam.snapshot(scene, new JobProgressAdapter<TextureCubeMap>() {

        @Override
        public void done(TextureCubeMap map) {
            generatePbrMaps(map, probe, envCam.getApplication(), listener);
        }
    });
    return probe;
}
Also used : LightProbe(com.jme3.light.LightProbe) TextureCubeMap(com.jme3.texture.TextureCubeMap)

Aggregations

EnvironmentCamera (com.jme3.environment.EnvironmentCamera)4 Vector3f (com.jme3.math.Vector3f)4 Node (com.jme3.scene.Node)4 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3 ToneMapFilter (com.jme3.post.filters.ToneMapFilter)3 Spatial (com.jme3.scene.Spatial)3 ChaseCamera (com.jme3.input.ChaseCamera)2 ActionListener (com.jme3.input.controls.ActionListener)2 KeyTrigger (com.jme3.input.controls.KeyTrigger)2 DirectionalLight (com.jme3.light.DirectionalLight)2 Quaternion (com.jme3.math.Quaternion)2 BoundingSphere (com.jme3.bounding.BoundingSphere)1 LightsDebugState (com.jme3.environment.util.LightsDebugState)1 LightProbe (com.jme3.light.LightProbe)1 Material (com.jme3.material.Material)1 BloomFilter (com.jme3.post.filters.BloomFilter)1 FXAAFilter (com.jme3.post.filters.FXAAFilter)1 SSAOFilter (com.jme3.post.ssao.SSAOFilter)1 Geometry (com.jme3.scene.Geometry)1 Sphere (com.jme3.scene.shape.Sphere)1