SunLight in jme3 - Java Game

Java examples for Game:JME3

Description

SunLight in jme3

Demo Code

package Chapter8;

import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.LightScatteringFilter;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Spatial;
import com.jme3.util.SkyFactory;

/**/* ww  w  . j av a 2s  .co m*/
 * test
 *
 * @author normenhansen
 */
public class SunLight extends SimpleApplication {

    private Vector3f lightDir = new Vector3f(-0.39f, -0.32f, -0.74f);
    private FilterPostProcessor fpp;
    private LightScatteringFilter sunLightFilter;

    public static void main(String[] args) {
        SunLight app = new SunLight();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(lightDir);
        sun.setColor(ColorRGBA.White.clone().multLocal(2));
        rootNode.addLight(sun);
        fpp = new FilterPostProcessor(assetManager);
        viewPort.addProcessor(fpp);
        sunLightFilter = new LightScatteringFilter(lightDir.mult(-3000));
        fpp.addFilter(sunLightFilter);
        Spatial sky = SkyFactory.createSky(assetManager,
                "Textures/Sky/Bright/BrightSky.dds", false);
        rootNode.attachChild(sky);
        cam.lookAtDirection(lightDir.negate(), Vector3f.UNIT_Y);
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}

Related Tutorials