Search in sources :

Example 1 with SSAOFilter

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

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

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

the class TestMultiViewsFilters method simpleInitApp.

public void simpleInitApp() {
    // create the geometry and attach it
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teaGeom.scale(3);
    teaGeom.getMaterial().setColor("GlowColor", ColorRGBA.Green);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    // Setup first view      
    cam.setViewPort(.5f, 1f, 0f, 0.5f);
    cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f));
    cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f));
    // Setup second view
    Camera cam2 = cam.clone();
    cam2.setViewPort(0f, 0.5f, 0f, 0.5f);
    cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
    cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));
    final ViewPort view2 = renderManager.createMainView("Bottom Left", cam2);
    view2.setClearFlags(true, true, true);
    view2.attachScene(rootNode);
    // Setup third view
    Camera cam3 = cam.clone();
    cam3.setName("cam3");
    cam3.setViewPort(0f, .5f, .5f, 1f);
    cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
    cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));
    final ViewPort view3 = renderManager.createMainView("Top Left", cam3);
    view3.setClearFlags(true, true, true);
    view3.attachScene(rootNode);
    // Setup fourth view
    Camera cam4 = cam.clone();
    cam4.setName("cam4");
    cam4.setViewPort(.5f, 1f, .5f, 1f);
    cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f));
    cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f));
    final ViewPort view4 = renderManager.createMainView("Top Right", cam4);
    view4.setClearFlags(true, true, true);
    view4.attachScene(rootNode);
    //        Camera cam5 = new Camera(200, 200);
    //        cam5.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
    //        cam5.setName("cam5");
    //        cam5.setViewPort(5.23f, 6.33f, 0.56f, 1.66f);
    //          this.setViewPortAreas(5.23f, 6.33f, 0.56f, 1.66f);
    //          this.setViewPortCamSize(200, 200);
    //          1046,1266,112,332
    Camera cam5 = cam.clone();
    cam5.setName("cam5");
    cam5.setViewPort(1046f / settings.getWidth(), 1266f / settings.getWidth(), 112f / settings.getHeight(), 332f / settings.getHeight());
    cam5.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
    cam5.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));
    final ViewPort view5 = renderManager.createMainView("center", cam5);
    view5.setClearFlags(true, true, true);
    view5.attachScene(rootNode);
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    final FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp2 = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp3 = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp4 = new FilterPostProcessor(assetManager);
    final FilterPostProcessor fpp5 = new FilterPostProcessor(assetManager);
    //  fpp.addFilter(new WaterFilter(rootNode, Vector3f.UNIT_Y.mult(-1)));
    fpp3.addFilter(new CartoonEdgeFilter());
    fpp2.addFilter(new CrossHatchFilter());
    final FogFilter ff = new FogFilter(ColorRGBA.Yellow, 0.7f, 2);
    fpp.addFilter(ff);
    final RadialBlurFilter rbf = new RadialBlurFilter(1, 10);
    //    rbf.setEnabled(false);
    fpp.addFilter(rbf);
    SSAOFilter f = new SSAOFilter(1.8899765f, 20.490374f, 0.4699998f, 0.1f);
    ;
    fpp4.addFilter(f);
    SSAOUI ui = new SSAOUI(inputManager, f);
    fpp5.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
    viewPort.addProcessor(fpp);
    view2.addProcessor(fpp2);
    view3.addProcessor(fpp3);
    view4.addProcessor(fpp4);
    view5.addProcessor(fpp5);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("press") && isPressed) {
                if (filterEnabled) {
                    viewPort.removeProcessor(fpp);
                    view2.removeProcessor(fpp2);
                    view3.removeProcessor(fpp3);
                    view4.removeProcessor(fpp4);
                    view5.removeProcessor(fpp5);
                } else {
                    viewPort.addProcessor(fpp);
                    view2.addProcessor(fpp2);
                    view3.addProcessor(fpp3);
                    view4.addProcessor(fpp4);
                    view5.addProcessor(fpp5);
                }
                filterEnabled = !filterEnabled;
            }
            if (name.equals("filter") && isPressed) {
                ff.setEnabled(!ff.isEnabled());
                rbf.setEnabled(!rbf.isEnabled());
            }
        }
    }, "press", "filter");
    inputManager.addMapping("press", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("filter", new KeyTrigger(KeyInput.KEY_F));
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) ViewPort(com.jme3.renderer.ViewPort) Camera(com.jme3.renderer.Camera)

Example 4 with SSAOFilter

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

the class TestMultiplesFilters method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(6.0344796f, 1.5054002f, 55.572033f));
    cam.setRotation(new Quaternion(0.0016069f, 0.9810479f, -0.008143323f, 0.19358753f));
    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f));
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);
    fpp = new FilterPostProcessor(assetManager);
    //  fpp.setNumSamples(4);
    ssaoFilter = new SSAOFilter(0.92f, 2.2f, 0.46f, 0.2f);
    final WaterFilter water = new WaterFilter(rootNode, new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f));
    water.setWaterHeight(-20);
    SSAOUI ui = new SSAOUI(inputManager, ssaoFilter);
    final BloomFilter bloom = new BloomFilter();
    final ColorOverlayFilter overlay = new ColorOverlayFilter(ColorRGBA.LightGray);
    fpp.addFilter(ssaoFilter);
    fpp.addFilter(water);
    fpp.addFilter(bloom);
    fpp.addFilter(overlay);
    viewPort.addProcessor(fpp);
    rootNode.attachChild(scene);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if ("toggleSSAO".equals(name) && isPressed) {
                if (ssaoFilter.isEnabled()) {
                    ssaoFilter.setEnabled(false);
                } else {
                    ssaoFilter.setEnabled(true);
                }
            }
            if ("toggleWater".equals(name) && isPressed) {
                if (water.isEnabled()) {
                    water.setEnabled(false);
                } else {
                    water.setEnabled(true);
                }
            }
            if ("toggleBloom".equals(name) && isPressed) {
                if (bloom.isEnabled()) {
                    bloom.setEnabled(false);
                } else {
                    bloom.setEnabled(true);
                }
            }
            if ("toggleOverlay".equals(name) && isPressed) {
                if (overlay.isEnabled()) {
                    overlay.setEnabled(false);
                } else {
                    overlay.setEnabled(true);
                }
            }
        }
    }, "toggleSSAO", "toggleBloom", "toggleWater", "toggleOverlay");
    inputManager.addMapping("toggleSSAO", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("toggleWater", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addMapping("toggleBloom", new KeyTrigger(KeyInput.KEY_3));
    inputManager.addMapping("toggleOverlay", new KeyTrigger(KeyInput.KEY_4));
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter) ColorOverlayFilter(com.jme3.post.filters.ColorOverlayFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WaterFilter(com.jme3.water.WaterFilter) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight)

Example 5 with SSAOFilter

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

the class AbstractVRViewManager method syncScreenProcessing.

/**
     * Sets the two views to use the list of {@link SceneProcessor processors}.
     * @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
     */
public void syncScreenProcessing(ViewPort sourceViewport) {
    if (environment != null) {
        if (getRightViewport() == null) {
            return;
        }
        if (environment.getApplication() != null) {
            // setup post processing filters
            if (getRightPostProcessor() == null) {
                rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
                leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
            }
            // clear out all filters & processors, to start from scratch
            getRightPostProcessor().removeAllFilters();
            getLeftPostProcessor().removeAllFilters();
            getLeftViewport().clearProcessors();
            getRightViewport().clearProcessors();
            // if we have no processors to sync, don't add the FilterPostProcessor
            if (sourceViewport.getProcessors().isEmpty())
                return;
            // add post processors we just made, which are empty
            getLeftViewport().addProcessor(getLeftPostProcessor());
            getRightViewport().addProcessor(getRightPostProcessor());
            // add them to the left viewport processor & clone them to the right
            for (SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
                if (sceneProcessor instanceof FilterPostProcessor) {
                    for (Filter f : ((FilterPostProcessor) sceneProcessor).getFilterList()) {
                        if (f instanceof TranslucentBucketFilter) {
                            // just remove this filter, we will add it at the end manually
                            ((FilterPostProcessor) sceneProcessor).removeFilter(f);
                        } else {
                            getLeftPostProcessor().addFilter(f);
                            // clone to the right
                            Filter f2;
                            if (f instanceof FogFilter) {
                                f2 = FilterUtil.cloneFogFilter((FogFilter) f);
                            } else if (f instanceof CartoonSSAO) {
                                f2 = new CartoonSSAO((CartoonSSAO) f);
                            } else if (f instanceof SSAOFilter) {
                                f2 = FilterUtil.cloneSSAOFilter((SSAOFilter) f);
                            } else if (f instanceof DirectionalLightShadowFilter) {
                                f2 = FilterUtil.cloneDirectionalLightShadowFilter(environment.getApplication().getAssetManager(), (DirectionalLightShadowFilter) f);
                            } else {
                                // dof, bloom, lightscattering etc.
                                f2 = f;
                            }
                            getRightPostProcessor().addFilter(f2);
                        }
                    }
                } else if (sceneProcessor instanceof VRDirectionalLightShadowRenderer) {
                    // shadow processing
                    // TODO: make right shadow processor use same left shadow maps for performance
                    VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
                    VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
                    dlsrRight.setLight(dlsr.getLight());
                    getRightViewport().getProcessors().add(0, dlsrRight);
                    getLeftViewport().getProcessors().add(0, sceneProcessor);
                }
            }
            // make sure each has a translucent filter renderer
            getLeftPostProcessor().addFilter(new TranslucentBucketFilter());
            getRightPostProcessor().addFilter(new TranslucentBucketFilter());
        } else {
            throw new IllegalStateException("The VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) VRDirectionalLightShadowRenderer(com.jme3.shadow.VRDirectionalLightShadowRenderer) FogFilter(com.jme3.post.filters.FogFilter) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) Filter(com.jme3.post.Filter) SSAOFilter(com.jme3.post.ssao.SSAOFilter) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) FogFilter(com.jme3.post.filters.FogFilter) SceneProcessor(com.jme3.post.SceneProcessor) CartoonSSAO(com.jme3.post.CartoonSSAO)

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