Search in sources :

Example 11 with SSAOFilter

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

the class SSAOUI method init.

private void init(InputManager inputManager) {
    System.out.println("----------------- SSAO UI Debugger --------------------");
    System.out.println("-- Sample Radius : press Y to increase, H to decrease");
    System.out.println("-- AO Intensity : press U to increase, J to decrease");
    System.out.println("-- AO scale : press I to increase, K to decrease");
    System.out.println("-- AO bias : press O to increase, P to decrease");
    System.out.println("-- Toggle AO on/off : press space bar");
    System.out.println("-- Use only AO : press Num pad 0");
    System.out.println("-- Output config declaration : press P");
    System.out.println("-------------------------------------------------------");
    inputManager.addMapping("sampleRadiusUp", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("sampleRadiusDown", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("intensityUp", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("intensityDown", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
    inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
    inputManager.addMapping("toggleApprox", new KeyTrigger(KeyInput.KEY_NUMPAD5));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggleUseAO") && keyPressed) {
                filter.setEnabled(!filter.isEnabled());
                // filter.setUseAo(!filter.isUseAo());
                System.out.println("use AO : " + filter.isEnabled());
            }
            if (name.equals("toggleApprox") && keyPressed) {
                filter.setApproximateNormals(!filter.isApproximateNormals());
                System.out.println("Approximate Normals : " + filter.isApproximateNormals());
            }
            if (name.equals("toggleUseOnlyAo") && keyPressed) {
                filter.setUseOnlyAo(!filter.isUseOnlyAo());
                System.out.println("use Only AO : " + filter.isUseOnlyAo());
            }
            if (name.equals("outputConfig") && keyPressed) {
                System.out.println("new SSAOFilter(" + filter.getSampleRadius() + "f," + filter.getIntensity() + "f," + filter.getScale() + "f," + filter.getBias() + "f);");
            }
        }
    };
    AnalogListener anl = new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("sampleRadiusUp")) {
                filter.setSampleRadius(filter.getSampleRadius() + 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("sampleRadiusDown")) {
                filter.setSampleRadius(filter.getSampleRadius() - 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("intensityUp")) {
                filter.setIntensity(filter.getIntensity() + 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("intensityDown")) {
                filter.setIntensity(filter.getIntensity() - 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("scaleUp")) {
                filter.setScale(filter.getScale() + 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("scaleDown")) {
                filter.setScale(filter.getScale() - 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("biasUp")) {
                filter.setBias(filter.getBias() + 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
            if (name.equals("biasDown")) {
                filter.setBias(filter.getBias() - 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
        }
    };
    inputManager.addListener(acl, "toggleUseAO", "toggleApprox", "toggleUseOnlyAo", "outputConfig");
    inputManager.addListener(anl, "sampleRadiusUp", "sampleRadiusDown", "intensityUp", "intensityDown", "scaleUp", "scaleDown", "biasUp", "biasDown");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 12 with SSAOFilter

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

the class TestSkeletonControlRefresh method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.White);
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(3.8664846f, 6.2704787f, 9.664585f));
    cam.setRotation(new Quaternion(-0.054774776f, 0.94064945f, -0.27974048f, -0.18418397f));
    makeHudText();
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey k = new TextureKey("Models/Oto/Oto.jpg", false);
    m.setTexture("ColorMap", assetManager.loadTexture(k));
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
            //setting a different material
            model.setMaterial(m.clone());
            model.setLocalScale(0.1f);
            model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
            control = model.getControl(AnimControl.class);
            channel = control.createChannel();
            channel.setAnim(animNames[(i + j) % 4]);
            channel.setLoopMode(LoopMode.DontLoop);
            SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
            //This is a workaround the issue. this call will make the SkeletonControl gather the targets again.
            //skeletonControl.setSpatial(model);
            skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
            skControls.add(skeletonControl);
            rootNode.attachChild(model);
        }
    }
    rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    setupFloor();
    inputManager.addListener(this, "toggleHWS");
    inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
    //        DirectionalLightShadowRenderer pssm = new DirectionalLightShadowRenderer(assetManager, 1024, 2);
    //        pssm.setLight(dl);
    //        viewPort.addProcessor(pssm);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    DirectionalLightShadowFilter sf = new DirectionalLightShadowFilter(assetManager, 1024, 2);
    sf.setLight(dl);
    fpp.addFilter(sf);
    fpp.addFilter(new SSAOFilter());
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) TextureKey(com.jme3.asset.TextureKey) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight)

Example 13 with SSAOFilter

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

the class TestTransparentSSAO method simpleInitApp.

public void simpleInitApp() {
    renderManager.setAlphaToCoverage(true);
    cam.setLocation(new Vector3f(0.14914267f, 0.58147097f, 4.7686534f));
    cam.setRotation(new Quaternion(-0.0044764364f, 0.9767943f, 0.21314798f, 0.020512417f));
    //        cam.setLocation(new Vector3f(2.0606942f, 3.20342f, 6.7860126f));
    //        cam.setRotation(new Quaternion(-0.017481906f, 0.98241085f, -0.12393151f, -0.13857932f));
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    Quad q = new Quad(20, 20);
    q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(5));
    Geometry geom = new Geometry("floor", q);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    geom.setMaterial(mat);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    geom.center();
    geom.setShadowMode(ShadowMode.Receive);
    TangentBinormalGenerator.generate(geom);
    rootNode.attachChild(geom);
    // create the geometry and attach it
    Spatial teaGeom = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    teaGeom.setQueueBucket(Bucket.Transparent);
    teaGeom.setShadowMode(ShadowMode.Cast);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(al);
    DirectionalLight dl1 = new DirectionalLight();
    dl1.setDirection(new Vector3f(1, -1, 1).normalizeLocal());
    dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl1);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //0.49997783f, 42.598858f, 35.999966f, 0.39299846f
    SSAOFilter ssao = new SSAOFilter();
    fpp.addFilter(ssao);
    SSAOUI ui = new SSAOUI(inputManager, ssao);
    viewPort.addProcessor(fpp);
}
Also used : Geometry(com.jme3.scene.Geometry) SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quad(com.jme3.scene.shape.Quad) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) AmbientLight(com.jme3.light.AmbientLight)

Example 14 with SSAOFilter

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

the class TestBatchNodeCluster method simpleInitApp.

//protected
//    protected Geometry player;
@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    batchNode = new SimpleBatchNode("BatchNode");
    xPosition.add(0);
    yPosition.add(0);
    zPosition.add(0);
    mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.White);
    mat1.setColor("GlowColor", ColorRGBA.Blue.mult(10));
    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.White);
    mat2.setColor("GlowColor", ColorRGBA.Red.mult(10));
    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat3.setColor("Color", ColorRGBA.White);
    mat3.setColor("GlowColor", ColorRGBA.Yellow.mult(10));
    mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat4.setColor("Color", ColorRGBA.White);
    mat4.setColor("GlowColor", ColorRGBA.Orange.mult(10));
    randomGenerator();
    //rootNode.attachChild(SkyFactory.createSky(
    //  assetManager, "Textures/SKY02.zip", false));
    inputManager.addMapping("Start Game", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addListener(al, new String[] { "Start Game" });
    cam.setLocation(new Vector3f(-34.403286f, 126.65158f, 434.791f));
    cam.setRotation(new Quaternion(0.022630932f, 0.9749435f, -0.18736298f, 0.11776358f));
    batchNode.batch();
    terrain = new Node("terrain");
    terrain.setLocalTranslation(50, 0, 50);
    terrain.attachChild(batchNode);
    flyCam.setMoveSpeed(100);
    rootNode.attachChild(terrain);
    Vector3f pos = new Vector3f(-40, 0, -40);
    batchNode.setLocalTranslation(pos);
    Arrow a = new Arrow(new Vector3f(0, 50, 0));
    Geometry g = new Geometry("a", a);
    g.setLocalTranslation(terrain.getLocalTranslation());
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.setColor("Color", ColorRGBA.Blue);
    g.setMaterial(m);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
    //        SSAOFilter ssao = new SSAOFilter(8.630104f,22.970434f,2.9299977f,0.2999997f);    
    //        fpp.addFilter(ssao);
    viewPort.addProcessor(fpp);
//   viewPort.setBackgroundColor(ColorRGBA.DarkGray);
}
Also used : Arrow(com.jme3.scene.debug.Arrow) NanoTimer(com.jme3.system.NanoTimer) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 15 with SSAOFilter

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

the class VRViewManagerOSVR 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 (rightViewport == null) {
        return;
    }
    if (environment != null) {
        if (environment.getApplication() != null) {
            // setup post processing filters
            if (rightPostProcessor == null) {
                rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
                leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
            }
            // clear out all filters & processors, to start from scratch
            rightPostProcessor.removeAllFilters();
            leftPostProcessor.removeAllFilters();
            leftViewport.clearProcessors();
            rightViewport.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
            leftViewport.addProcessor(leftPostProcessor);
            rightViewport.addProcessor(rightPostProcessor);
            // 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 {
                            leftPostProcessor.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;
                            }
                            rightPostProcessor.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());
                    rightViewport.getProcessors().add(0, dlsrRight);
                    leftViewport.getProcessors().add(0, sceneProcessor);
                }
            }
            // make sure each has a translucent filter renderer
            leftPostProcessor.addFilter(new TranslucentBucketFilter());
            rightPostProcessor.addFilter(new TranslucentBucketFilter());
        } else {
            throw new IllegalStateException("This 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) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) Filter(com.jme3.post.Filter) SSAOFilter(com.jme3.post.ssao.SSAOFilter) FogFilter(com.jme3.post.filters.FogFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) 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