Shadow effect jme3 - Java Game

Java examples for Game:JME3

Description

Shadow effect jme3

Demo Code

package Effects;//w  w  w.ja  v  a2  s  .  c  o m

import template.*;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.DirectionalLightShadowRenderer;

/**
 * test
 *
 * @author normenhansen
 */
public class ShadowDirectional extends SimpleApplication {

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

    @Override
    public void simpleInitApp() {
        flyCam.setMoveSpeed(50f);
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(.3f, -0.5f, -0.5f));
        rootNode.addLight(sun);

        DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(
                assetManager, 1024, 2);
        dlsr.setLight(sun);

        viewPort.addProcessor(dlsr);

        assetManager.registerLocator("town.zip", ZipLocator.class);
        Spatial sceneGeo = assetManager.loadModel("main.scene");
        rootNode.attachChild(sceneGeo);

        rootNode.setShadowMode(ShadowMode.Off);
        sceneGeo.setShadowMode(ShadowMode.CastAndReceive);

    }

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

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

Related Tutorials