Java Code Examples for com.jme3.post.FilterPostProcessor#addFilter()

The following examples show how to use com.jme3.post.FilterPostProcessor#addFilter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCartoonEdge.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setupFilters(){
    if (renderer.getCaps().contains(Caps.GLSL100)){
        fpp=new FilterPostProcessor(assetManager);
        //fpp.setNumSamples(4);
        CartoonEdgeFilter toon=new CartoonEdgeFilter();
        toon.setEdgeColor(ColorRGBA.Yellow);
        fpp.addFilter(toon);
        viewPort.addProcessor(fpp);
    }
}
 
Example 2
Source File: TestFog.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(50);
    Node mainScene=new Node();
    cam.setLocation(new Vector3f(-34.74095f, 95.21318f, -287.4945f));
    cam.setRotation(new Quaternion(0.023536969f, 0.9361278f, -0.016098259f, -0.35050195f));

    // load sky
    mainScene.attachChild(SkyFactory.createSky(assetManager, 
            "Textures/Sky/Bright/BrightSky.dds", 
            SkyFactory.EnvMapType.CubeMap));
    createTerrain(mainScene);



    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir=new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    mainScene.addLight(sun);

    rootNode.attachChild(mainScene);

    fpp=new FilterPostProcessor(assetManager);
    //fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if( numSamples > 0 ) {
        fpp.setNumSamples(numSamples); 
    }
    fog=new FogFilter();
    fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
    fog.setFogDistance(155);
    fog.setFogDensity(1.0f);
    fpp.addFilter(fog);
    viewPort.addProcessor(fpp);
    initInputs();
}
 
Example 3
Source File: TestPostFilters.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupFilters() {
    if (renderer.getCaps().contains(Caps.GLSL100)) {
        fpp = new FilterPostProcessor(assetManager);
        //     fpp.setNumSamples(4);
        // fpp.setNumSamples(4);
        //fpp.addFilter(new ColorOverlayFilter(ColorRGBA.LightGray));
        fpp.addFilter(new RadialBlurFilter());
        fade = new FadeFilter(1.0f);
        fpp.addFilter(fade);


        viewPort.addProcessor(fpp);
    }
}
 
Example 4
Source File: TestHoverTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");

    flyCam.setEnabled(false);
    ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
    chaseCam.setSmoothMotion(true);
    chaseCam.setMaxDistance(100000);
    chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);

    Geometry tankGeom = (Geometry) tank.getChild(0);
    LodControl control = new LodControl();
    tankGeom.addControl(control);
    rootNode.attachChild(tank);

    Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
    dl.setDirection(lightDir);

    Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
    DirectionalLight dl2 = new DirectionalLight();
    dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
    dl2.setDirection(lightDir2);

    rootNode.addLight(dl);
    rootNode.addLight(dl2);
    rootNode.attachChild(tank);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
    bf.setBloomIntensity(2.0f);
    bf.setExposurePower(1.3f);
    fpp.addFilter(bf);
    BloomUI bui = new BloomUI(inputManager, bf);
    viewPort.addProcessor(fpp);
}
 
Example 5
Source File: TestEverything.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupHdr(){
    if (renderer.getCaps().contains(Caps.GLSL100)){
        toneMapFilter = new ToneMapFilter();
        toneMapFilter.setWhitePoint(new Vector3f(3f, 3f, 3f));
        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.addFilter(toneMapFilter);
        viewPort.addProcessor(fpp);

//        setPauseOnLostFocus(false);
    }
}
 
Example 6
Source File: TestCartoonEdge.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupFilters(){
    if (renderer.getCaps().contains(Caps.GLSL100)){
        fpp=new FilterPostProcessor(assetManager);
        //fpp.setNumSamples(4);
        int numSamples = getContext().getSettings().getSamples();
        if( numSamples > 0 ) {
            fpp.setNumSamples(numSamples); 
        }
        CartoonEdgeFilter toon=new CartoonEdgeFilter();
        toon.setEdgeColor(ColorRGBA.Yellow);
        fpp.addFilter(toon);
        viewPort.addProcessor(fpp);
    }
}
 
Example 7
Source File: TestFog.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    Node mainScene=new Node();
    cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
    cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));

    // load sky
    mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));

    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName());
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName());
    }
    Spatial scene = assetManager.loadModel("main.scene");

    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir=new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);


    mainScene.attachChild(scene);
    rootNode.attachChild(mainScene);

    fpp=new FilterPostProcessor(assetManager);
    //fpp.setNumSamples(4);
    fog=new FogFilter();
    fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
    fog.setFogDistance(155);
    fog.setFogDensity(2.0f);
    fpp.addFilter(fog);
    viewPort.addProcessor(fpp);
    initInputs();
}
 
Example 8
Source File: TestPostFiltersCompositing.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(0.028406568f, 2.015769f, 7.386517f));
    cam.setRotation(new Quaternion(-1.0729783E-5f, 0.9999721f, -0.0073241726f, -0.0014647911f));


    makeScene();

    //Creating the main view port post processor
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(new ColorOverlayFilter(ColorRGBA.Blue));
    viewPort.addProcessor(fpp);

    //creating a frame buffer for the mainviewport
    FrameBuffer mainVPFrameBuffer = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
    Texture2D mainVPTexture = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
    mainVPFrameBuffer.addColorTexture(mainVPTexture);
    mainVPFrameBuffer.setDepthBuffer(Image.Format.Depth);
    viewPort.setOutputFrameBuffer(mainVPFrameBuffer);

    //creating the post processor for the gui viewport
    final FilterPostProcessor guifpp = new FilterPostProcessor(assetManager);
    guifpp.setFrameBufferFormat(Image.Format.RGBA8);
    guifpp.addFilter(new ColorOverlayFilter(ColorRGBA.Red));
    //this will compose the main viewport texture with the guiviewport back buffer.
    //Note that you can switch the order of the filters so that guiviewport filters are applied or not to the main viewport texture
    guifpp.addFilter(new ComposeFilter(mainVPTexture));

    guiViewPort.addProcessor(guifpp);
    
    //compositing is done by mixing texture depending on the alpha channel, 
    //it's important that the guiviewport clear color alpha value is set to 0
    guiViewPort.setBackgroundColor(ColorRGBA.BlackNoAlpha);
    guiViewPort.setClearColor(true);


}
 
Example 9
Source File: TestMultiplesFilters.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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));

    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName());
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName());
    }
    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));
    
}
 
Example 10
Source File: TestMultiPostWater.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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(1.7f));
        mainScene.addLight(sun);

        flyCam.setMoveSpeed(100);

        //cam.setLocation(new Vector3f(-700, 100, 300));
        //cam.setRotation(new Quaternion().fromAngleAxis(0.5f, Vector3f.UNIT_Z));
        cam.setLocation(new Vector3f(-327.21957f, 251.6459f, 126.884346f));
        cam.setRotation(new Quaternion().fromAngles(new float[]{FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0}));


        Spatial sky = SkyFactory.createSky(assetManager, 
                "Scenes/Beach/FullskiesSunset0068.dds", EnvMapType.CubeMap);
        sky.setLocalScale(350);

        mainScene.attachChild(sky);
        cam.setFrustumFar(4000);



        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);

        water = new WaterFilter(rootNode, lightDir);
        water.setCenter(new Vector3f(9.628218f, -15.830074f, 199.23595f));
        water.setRadius(260);
        water.setWaveScale(0.003f);
        water.setMaxAmplitude(2f);
        water.setFoamExistence(new Vector3f(1f, 4, 0.5f));
        water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
        water.setRefractionStrength(0.2f);
        water.setWaterHeight(WATER_HEIGHT);
        fpp.addFilter(water);

        WaterFilter water2 = new WaterFilter(rootNode, lightDir);
        water2.setCenter(new Vector3f(-280.46027f, -24.971727f, -271.71976f));
        water2.setRadius(260);
        water2.setWaterHeight(WATER_HEIGHT);
        water2.setUseFoam(false);
        water2.setUseRipples(false);
        water2.setDeepWaterColor(ColorRGBA.Brown);
        water2.setWaterColor(ColorRGBA.Brown.mult(2.0f));
        water2.setWaterTransparency(0.2f);
        water2.setMaxAmplitude(0.3f);
        water2.setWaveScale(0.008f);
        water2.setSpeed(0.7f);
        water2.setShoreHardness(1.0f);
        water2.setRefractionConstant(0.2f);
        water2.setShininess(0.3f);
        water2.setSunScale(1.0f);
        water2.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f));
        fpp.addFilter(water2);


        WaterFilter water3 = new WaterFilter(rootNode, lightDir);
        water3.setCenter(new Vector3f(319.6663f, -18.367947f, -236.67674f));
        water3.setRadius(260);
        water3.setWaterHeight(WATER_HEIGHT);
        water3.setWaveScale(0.003f);
        water3.setMaxAmplitude(2f);
        water3.setFoamExistence(new Vector3f(1f, 4, 0.5f));
        water3.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
        water3.setRefractionStrength(0.2f);
        water3.setDeepWaterColor(ColorRGBA.Red);
        water3.setWaterColor(ColorRGBA.Red.mult(2.0f));
        water3.setLightColor(ColorRGBA.Red);
        fpp.addFilter(water3);

        viewPort.addProcessor(fpp);

        //fpp.setNumSamples(4);
    }
 
Example 11
Source File: TestWalkingChar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void setupFilter() {
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
    fpp.addFilter(bloom);
    viewPort.addProcessor(fpp);
}
 
Example 12
Source File: TestWalkingChar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setupFilter() {
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
    fpp.addFilter(bloom);
    viewPort.addProcessor(fpp);
}
 
Example 13
Source File: TestPostWaterLake.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
  //  cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));

    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));

    File file = new File("wildhouse.zip");
    
    if (file.exists()) {
        useHttp = false;
    }
    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName());
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName());
    }
    Spatial scene = assetManager.loadModel("main.scene");
    rootNode.attachChild(scene);

    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);        
    final WaterFilter water = new WaterFilter(rootNode, lightDir);
    water.setWaterHeight(-20);
    water.setUseFoam(false);
    water.setUseRipples(false);
    water.setDeepWaterColor(ColorRGBA.Brown);
    water.setWaterColor(ColorRGBA.Brown.mult(2.0f));
    water.setWaterTransparency(0.2f);
    water.setMaxAmplitude(0.3f);
    water.setWaveScale(0.008f);
    water.setSpeed(0.7f);
    water.setShoreHardness(1.0f);
    water.setRefractionConstant(0.2f);
    water.setShininess(0.3f);
    water.setSunScale(1.0f);
    water.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f));
    fpp.addFilter(water);
    viewPort.addProcessor(fpp);

    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
          if(isPressed){
              if(water.isUseHQShoreline()){
                  water.setUseHQShoreline(false);
              }else{
                  water.setUseHQShoreline(true);
              }
          }
        }
    }, "HQ");

    inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE));
}
 
Example 14
Source File: TestBloom.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
    //cam.setFrustumFar(1000);


    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));




    Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);
   


    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0,0,10);

    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);

  

    Geometry soil = new Geometry("soil", new Box(800, 10, 700));
    soil.setLocalTranslation(0, -13, 550);
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);

    DirectionalLight light=new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);

    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, 
            "Textures/Sky/Bright/FullskiesBlueClear03.dds", 
            EnvMapType.CubeMap);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);

    fpp=new FilterPostProcessor(assetManager);
   // fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if( numSamples > 0 ) {
        fpp.setNumSamples(numSamples); 
    }
    
    BloomFilter bloom=new BloomFilter();
    bloom.setDownSamplingFactor(2);
    bloom.setBlurScale(1.37f);
    bloom.setExposurePower(3.30f);
    bloom.setExposureCutOff(0.2f);
    bloom.setBloomIntensity(2.45f);
    BloomUI ui=new BloomUI(inputManager, bloom);
   

    viewPort.addProcessor(fpp);
    fpp.addFilter(bloom);
    initInputs();

}
 
Example 15
Source File: TestLightScattering.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        // put the camera in a bad position
        cam.setLocation(new Vector3f(55.35316f, -0.27061665f, 27.092093f));
        cam.setRotation(new Quaternion(0.010414706f, 0.9874893f, 0.13880467f, -0.07409228f));
//        cam.setDirection(new Vector3f(0,-0.5f,1.0f));
//        cam.setLocation(new Vector3f(0, 300, -500));
        //cam.setFrustumFar(1000);
        flyCam.setMoveSpeed(10);
        Material mat = assetManager.loadMaterial("Textures/Terrain/Rocky/Rocky.j3m");
        Spatial scene = assetManager.loadModel("Models/Terrain/Terrain.mesh.xml");
        TangentBinormalGenerator.generate(((Geometry)((Node)scene).getChild(0)).getMesh());
        scene.setMaterial(mat);
        scene.setShadowMode(ShadowMode.CastAndReceive);
        scene.setLocalScale(400);
        scene.setLocalTranslation(0, -10, -120);

        rootNode.attachChild(scene);

        // load sky
        rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false));

        DirectionalLight sun = new DirectionalLight();
        Vector3f lightDir = new Vector3f(-0.12f, -0.3729129f, 0.74847335f);
        sun.setDirection(lightDir);
        sun.setColor(ColorRGBA.White.clone().multLocal(2));
        scene.addLight(sun);

        PssmShadowRenderer pssmRenderer = new PssmShadowRenderer(assetManager,1024,4);
        pssmRenderer.setDirection(lightDir);
        pssmRenderer.setShadowIntensity(0.55f);
     //   viewPort.addProcessor(pssmRenderer);

        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
//        SSAOFilter ssaoFilter= new SSAOFilter(viewPort, new SSAOConfig(0.36f,1.8f,0.84f,0.16f,false,true));
//        fpp.addFilter(ssaoFilter);


//           Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
//        mat2.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
//
//        Sphere lite=new Sphere(8, 8, 10.0f);
//        Geometry lightSphere=new Geometry("lightsphere", lite);
//        lightSphere.setMaterial(mat2);
        Vector3f lightPos = lightDir.multLocal(-3000);
//        lightSphere.setLocalTranslation(lightPos);
        // rootNode.attachChild(lightSphere);
        LightScatteringFilter filter = new LightScatteringFilter(lightPos);
        LightScatteringUI ui = new LightScatteringUI(inputManager, filter);
        fpp.addFilter(filter);
//fpp.setNumSamples(4);
        //fpp.addFilter(new RadialBlurFilter(0.3f,15.0f));
        //    SSAOUI ui=new SSAOUI(inputManager, ssaoFilter.getConfig());

        viewPort.addProcessor(fpp);
    }
 
Example 16
Source File: TestLightScattering.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        // put the camera in a bad position
        cam.setLocation(new Vector3f(55.35316f, -0.27061665f, 27.092093f));
        cam.setRotation(new Quaternion(0.010414706f, 0.9874893f, 0.13880467f, -0.07409228f));
//        cam.setDirection(new Vector3f(0,-0.5f,1.0f));
//        cam.setLocation(new Vector3f(0, 300, -500));
        //cam.setFrustumFar(1000);
        flyCam.setMoveSpeed(10);
        Material mat = assetManager.loadMaterial("Textures/Terrain/Rocky/Rocky.j3m");
        Spatial scene = assetManager.loadModel("Models/Terrain/Terrain.mesh.xml");
        TangentBinormalGenerator.generate(((Geometry)((Node)scene).getChild(0)).getMesh());
        scene.setMaterial(mat);
        scene.setShadowMode(ShadowMode.CastAndReceive);
        scene.setLocalScale(400);
        scene.setLocalTranslation(0, -10, -120);

        rootNode.attachChild(scene);

        // load sky
        rootNode.attachChild(SkyFactory.createSky(assetManager,
                "Textures/Sky/Bright/FullskiesBlueClear03.dds", 
                SkyFactory.EnvMapType.CubeMap));

        DirectionalLight sun = new DirectionalLight();
        Vector3f lightDir = new Vector3f(-0.12f, -0.3729129f, 0.74847335f);
        sun.setDirection(lightDir);
        sun.setColor(ColorRGBA.White.clone().multLocal(2));
        scene.addLight(sun);


        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        int numSamples = getContext().getSettings().getSamples();
        if (numSamples > 0) {
            fpp.setNumSamples(numSamples);
        }
        Vector3f lightPos = lightDir.multLocal(-3000);
        LightScatteringFilter filter = new LightScatteringFilter(lightPos);
        LightScatteringUI ui = new LightScatteringUI(inputManager, filter);
        fpp.addFilter(filter);
        viewPort.addProcessor(fpp);
    }
 
Example 17
Source File: TestCubeCluster.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {


        blue = new GeometryBatch("blue");
        brown = new GeometryBatch("brown");
        pink = new GeometryBatch("pink");
        orange = new GeometryBatch("orange");
        mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat1.setColor("Color", ColorRGBA.White);
        mat1.setColor("GlowColor", ColorRGBA.Blue.mult(10));
        blue.setMaterial(mat1);
        mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat2.setColor("Color", ColorRGBA.White);
        mat2.setColor("GlowColor", ColorRGBA.Red.mult(10));
        brown.setMaterial(mat2);
        mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat3.setColor("Color", ColorRGBA.White);
        mat3.setColor("GlowColor", ColorRGBA.Yellow.mult(10));
        pink.setMaterial(mat3);
        mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat4.setColor("Color", ColorRGBA.White);
        mat4.setColor("GlowColor", ColorRGBA.Orange.mult(10));
        orange.setMaterial(mat4);
        //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));


        //ChaseCamera c = new ChaseCamera();
        //flyCam.setEnabled(false);
        xPosition.add(0);
        yPosition.add(0);
        zPosition.add(0);


        randomGenerator();


        List<BatchedGeometry> l = blue.batch(blueList);
//        for (Iterator<BatchedGeometry> it = l.iterator(); it.hasNext();) {
//            BatchedGeometry batchedGeometry = it.next();
//            batchedGeometry.addControl(new MyControl());
//        }
        l = brown.batch(brownList);
//        for (Iterator<BatchedGeometry> it = l.iterator(); it.hasNext();) {
//            BatchedGeometry batchedGeometry = it.next();
//            batchedGeometry.addControl(new MyControl());
//        }
        l = pink.batch(pinkList);
//        for (Iterator<BatchedGeometry> it = l.iterator(); it.hasNext();) {
//            BatchedGeometry batchedGeometry = it.next();
//            batchedGeometry.addControl(new MyControl());
//        }

        l = orange.batch(orangeList);
//        for (Iterator<BatchedGeometry> it = l.iterator(); it.hasNext();) {
//            BatchedGeometry batchedGeometry = it.next();
//            batchedGeometry.addControl(new MyControl());
//            
//        }
        //    GeometryBatchFactory.optimize(terrain);
        terrain = new Node("terrain");
        terrain.setLocalTranslation(50, 0, 50);
        terrain.attachChild(blue);
        terrain.attachChild(brown);
        terrain.attachChild(pink);
        terrain.attachChild(orange);
        flyCam.setMoveSpeed(100);
        rootNode.attachChild(terrain);
        Vector3f pos = new Vector3f(-40, 0, -40);
        blue.setLocalTranslation(pos);
        brown.setLocalTranslation(pos);
        pink.setLocalTranslation(pos);
        orange.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);
        //    rootNode.attachChild(g);


        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);
    }
 
Example 18
Source File: TestSpotLightShadows.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setupLighting() {
        AmbientLight al = new AmbientLight();
        al.setColor(ColorRGBA.White.mult(0.02f));
        rootNode.addLight(al);

        rootNode.setShadowMode(ShadowMode.CastAndReceive);

        spot = new SpotLight();

        spot.setSpotRange(1000);
        spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
        spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
        spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
        spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
        spot.setColor(ColorRGBA.White.mult(2));
        rootNode.addLight(spot);


//        PointLight pl=new PointLight();
//      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
//      pl.setRadius(1000);     
//      pl.setColor(ColorRGBA.White.mult(2));
//      rootNode.addLight(pl);
        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
        lightMdl.setLocalScale(5);
        rootNode.attachChild(lightMdl);

//        DirectionalLight dl = new DirectionalLight();
//        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
//        dl.setColor(ColorRGBA.White.mult(0.7f));
//        rootNode.addLight(dl);


        final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
        slsr.setLight(spot);       
        slsr.setShadowIntensity(0.5f);
        slsr.setShadowZExtend(100);
        slsr.setShadowZFadeLength(5);
        slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);   
        viewPort.addProcessor(slsr);

        SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
        slsf.setLight(spot);    
        slsf.setShadowIntensity(0.5f);
        slsf.setShadowZExtend(100);
        slsf.setShadowZFadeLength(5);
        slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);  
        slsf.setEnabled(false);
        
        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.addFilter(slsf);
        viewPort.addProcessor(fpp);
        
        ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);

        inputManager.addListener(new ActionListener() {
            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                if (name.equals("stop") && isPressed) {
                    stop = !stop;
                 //   slsr.displayFrustum();
                    System.out.println("pos : " + spot.getPosition());
                    System.out.println("dir : " + spot.getDirection());
                }
            }
        }, "stop");

        inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_1));
        flyCam.setDragToRotate(true);
    }
 
Example 19
Source File: TestBatchNodeCluster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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);
    }
 
Example 20
Source File: TestCinematic.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void createScene() {

        model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
        model.center();
        model.setShadowMode(ShadowMode.CastAndReceive);
        rootNode.attachChild(model);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Cyan);

        teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
        teapot.setLocalTranslation(10, 0, 10);
        teapot.setMaterial(mat);
        teapot.setShadowMode(ShadowMode.CastAndReceive);
        rootNode.attachChild(teapot);

        Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        matSoil.setBoolean("UseMaterialColors", true);
        matSoil.setColor("Ambient", ColorRGBA.Gray);
        matSoil.setColor("Diffuse", ColorRGBA.Green);
        matSoil.setColor("Specular", ColorRGBA.Black);

        Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -6.0f, 0), 50, 1, 50));
        soil.setMaterial(matSoil);
        soil.setShadowMode(ShadowMode.Receive);
        rootNode.attachChild(soil);
        DirectionalLight light = new DirectionalLight();
        light.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
        light.setColor(ColorRGBA.White.mult(1.5f));
        rootNode.addLight(light);

        fpp = new FilterPostProcessor(assetManager);
        fade = new FadeFilter();
        fpp.addFilter(fade);
        
        if (renderer.getCaps().contains(Caps.GLSL100)){
            PssmShadowRenderer pssm = new PssmShadowRenderer(assetManager, 512, 1);
            pssm.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
            pssm.setShadowIntensity(0.4f);
            viewPort.addProcessor(pssm);
            viewPort.addProcessor(fpp);
        }
    }