Java Code Examples for com.jme3.scene.Spatial#addLight()

The following examples show how to use com.jme3.scene.Spatial#addLight() . 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: TestObjGroupsLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {

    // load scene with following structure:
    // Chair 1 (just mesh without name) and named groups: Chair 2, Pillow 2, Podium
    Spatial scene = assetManager.loadModel(new ModelKey("OBJLoaderTest/TwoChairs.obj"));
    // add light to make it visible
    scene.addLight(new AmbientLight(ColorRGBA.White));
    // attach scene to the root
    rootNode.attachChild(scene);
    
    // configure camera for best scene viewing
    cam.setLocation(new Vector3f(-3, 4, 3));
    cam.lookAtDirection(new Vector3f(0, -0.5f, -1), Vector3f.UNIT_Y);
    flyCam.setMoveSpeed(10);
    
    // create display to indicate pointed geometry name
    pointerDisplay = new BitmapText(guiFont);
    pointerDisplay.setBox(new Rectangle(0, settings.getHeight(), settings.getWidth(), settings.getHeight()/2));
    pointerDisplay.setAlignment(BitmapFont.Align.Center);
    pointerDisplay.setVerticalAlignment(BitmapFont.VAlign.Center);
    guiNode.attachChild(pointerDisplay);
    
    initCrossHairs();
}
 
Example 2
Source File: TestMousePick.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Spatial makeCharacter() {
    // load a character from jme3test-test-data
    Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    return golem;
}
 
Example 3
Source File: HelloPicking.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Spatial makeCharacter() {
  // load a character from jme3test-test-data
  Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
  golem.scale(0.5f);
  golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

  // We must add a light to make the model visible
  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
  golem.addLight(sun);
  return golem;
}
 
Example 4
Source File: TestPostFiltersCompositing.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void makeScene() {
    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap));
    //assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class);
    Spatial scene = assetManager.loadModel("Models/Test/CornellBox.j3o");
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.4790551f, -0.39247334f, -0.7851566f));
    scene.addLight(sun);
    rootNode.attachChild(scene);

}
 
Example 5
Source File: TestSceneLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    File file = new File("wildhouse.zip");
    if (!file.exists()) {
        useHttp = true;
    }
    
    this.flyCam.setMoveSpeed(10);

    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, 
            "Textures/Sky/Bright/BrightSky.dds", 
            SkyFactory.EnvMapType.CubeMap));
    
    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");

    AmbientLight al = new AmbientLight();
    scene.addLight(al);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(0.69077975f, -0.6277887f, -0.35875428f).normalizeLocal());
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);

    rootNode.attachChild(scene);
}
 
Example 6
Source File: TestSceneLoading.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);

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

    File file = new File("wildhouse.zip");
    if (!file.exists()) {
        useHttp = true;
    }
    // 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");

    AmbientLight al = new AmbientLight();
    scene.addLight(al);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(0.69077975f, -0.6277887f, -0.35875428f).normalizeLocal());
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);

    rootNode.attachChild(scene);
}
 
Example 7
Source File: TestMousePick.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Spatial makeCharacter() {
    // load a character from jme3test-test-data
    Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    return golem;
}
 
Example 8
Source File: HelloPicking.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Spatial makeCharacter() {
  // load a character from jme3test-test-data
  Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
  golem.scale(0.5f);
  golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

  // We must add a light to make the model visible
  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
  golem.addLight(sun);
  return golem;
}
 
Example 9
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 10
Source File: TestSceneWater.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 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));

        
        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");

        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);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
           //add lightPos Geometry
        Sphere lite=new Sphere(8, 8, 3.0f);
        Geometry lightSphere=new Geometry("lightsphere", lite);
        lightSphere.setMaterial(mat);
        Vector3f lightPos=lightDir.multLocal(-400);
        lightSphere.setLocalTranslation(lightPos);
        rootNode.attachChild(lightSphere);


        SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager);
        waterProcessor.setReflectionScene(mainScene);
        waterProcessor.setDebug(false);
        waterProcessor.setLightPosition(lightPos);
        waterProcessor.setRefractionClippingOffset(1.0f);


        //setting the water plane
        Vector3f waterLocation=new Vector3f(0,-20,0);
        waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y)));
        WaterUI waterUi=new WaterUI(inputManager, waterProcessor);
        waterProcessor.setWaterColor(ColorRGBA.Brown);
        waterProcessor.setDebug(true);
        //lower render size for higher performance
//        waterProcessor.setRenderSize(128,128);
        //raise depth to see through water
//        waterProcessor.setWaterDepth(20);
        //lower the distortion scale if the waves appear too strong
//        waterProcessor.setDistortionScale(0.1f);
        //lower the speed of the waves if they are too fast
//        waterProcessor.setWaveSpeed(0.01f);

        Quad quad = new Quad(400,400);

        //the texture coordinates define the general size of the waves
        quad.scaleTextureCoordinates(new Vector2f(6f,6f));

        Geometry water=new Geometry("water", quad);
        water.setShadowMode(ShadowMode.Receive);
        water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
        water.setMaterial(waterProcessor.getMaterial());
        water.setLocalTranslation(-200, -20, 250);

        rootNode.attachChild(water);

        viewPort.addProcessor(waterProcessor);

        mainScene.attachChild(scene);
        rootNode.attachChild(mainScene);
    }
 
Example 11
Source File: RemoveElementsOperation.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@JmeThread
private void restoreLight(@NotNull final Element element, @NotNull final Light toRestore) {
    final Spatial parent = (Spatial) element.getParent();
    parent.addLight(toRestore);
}
 
Example 12
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 13
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 14
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 15
Source File: TestSceneWater.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        File file = new File("wildhouse.zip");
        if (!file.exists()) {
            useHttp = true;
        }
        
        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", 
                SkyFactory.EnvMapType.CubeMap));

                
        // create the geometry and attach it
        // load the level from zip or http zip
        if (useHttp) {
            assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
        } else {
            assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
        }
        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);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
           //add lightPos Geometry
        Sphere lite=new Sphere(8, 8, 3.0f);
        Geometry lightSphere=new Geometry("lightsphere", lite);
        lightSphere.setMaterial(mat);
        Vector3f lightPos=lightDir.multLocal(-400);
        lightSphere.setLocalTranslation(lightPos);
        rootNode.attachChild(lightSphere);


        SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager);
        waterProcessor.setReflectionScene(mainScene);
        waterProcessor.setDebug(false);
        waterProcessor.setLightPosition(lightPos);
        waterProcessor.setRefractionClippingOffset(1.0f);


        //setting the water plane
        Vector3f waterLocation=new Vector3f(0,-20,0);
        waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y)));
        WaterUI waterUi=new WaterUI(inputManager, waterProcessor);
        waterProcessor.setWaterColor(ColorRGBA.Brown);
        waterProcessor.setDebug(true);
        //lower render size for higher performance
//        waterProcessor.setRenderSize(128,128);
        //raise depth to see through water
//        waterProcessor.setWaterDepth(20);
        //lower the distortion scale if the waves appear too strong
//        waterProcessor.setDistortionScale(0.1f);
        //lower the speed of the waves if they are too fast
//        waterProcessor.setWaveSpeed(0.01f);

        Quad quad = new Quad(400,400);

        //the texture coordinates define the general size of the waves
        quad.scaleTextureCoordinates(new Vector2f(6f,6f));

        Geometry water=new Geometry("water", quad);
        water.setShadowMode(ShadowMode.Receive);
        water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
        water.setMaterial(waterProcessor.getMaterial());
        water.setLocalTranslation(-200, -20, 250);

        rootNode.attachChild(water);

        viewPort.addProcessor(waterProcessor);

        mainScene.attachChild(scene);
        rootNode.attachChild(mainScene);
    }
 
Example 16
Source File: TestPostWaterLake.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    File file = new File("wildhouse.zip");
    if (!file.exists()) {
        useHttp = true;
    }
    
    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", 
            SkyFactory.EnvMapType.CubeMap));
    
    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator(
                "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", 
                HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    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() {

        @Override
        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 17
Source File: TestMultiplesFilters.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    File file = new File("wildhouse.zip");
    if (!file.exists()) {
        useHttp = true;
    }
    
    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", 
            SkyFactory.EnvMapType.CubeMap));

    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator(
                "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/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() {

        @Override
        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 18
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);
    }