Search in sources :

Example 71 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class TestEverything method setupLighting.

public void setupLighting() {
    boolean hdr = false;
    if (hdrRender != null) {
        hdr = hdrRender.isEnabled();
    }
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(lightDir);
    if (hdr) {
        dl.setColor(new ColorRGBA(3, 3, 3, 1));
    } else {
        dl.setColor(new ColorRGBA(.9f, .9f, .9f, 1));
    }
    rootNode.addLight(dl);
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, 0, -1).normalizeLocal());
    if (hdr) {
        dl.setColor(new ColorRGBA(1, 1, 1, 1));
    } else {
        dl.setColor(new ColorRGBA(.4f, .4f, .4f, 1));
    }
    rootNode.addLight(dl);
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight)

Example 72 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class TestManyLightsSingle method simpleInitApp.

@Override
public void simpleInitApp() {
    renderManager.setPreferredLightMode(lm);
    renderManager.setSinglePassLightBatchSize(6);
    flyCam.setMoveSpeed(10);
    Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
    rootNode.attachChild(scene);
    Node n = (Node) rootNode.getChild(0);
    final LightList lightList = n.getWorldLightList();
    final Geometry g = (Geometry) n.getChild("Grid-geom-1");
    g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    /* A colored lit cube. Needs light source! */
    Box boxMesh = new Box(1f, 1f, 1f);
    final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
    Material boxMat = g.getMaterial().clone();
    boxMat.clearParam("DiffuseMap");
    boxMat.setBoolean("UseMaterialColors", true);
    boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    boxMat.setColor("Diffuse", ColorRGBA.Blue);
    boxGeo.setMaterial(boxMat);
    final Node cubeNodes = new Node();
    n.attachChild(cubeNodes);
    int nb = 0;
    for (Light light : lightList) {
        nb++;
        PointLight p = (PointLight) light;
        if (nb > 60) {
            n.removeLight(light);
        } else {
            LightNode ln = new LightNode("l", light);
            n.attachChild(ln);
            ln.setLocalTranslation(p.getPosition());
            int rand = FastMath.nextRandomInt(0, 3);
            switch(rand) {
                case 0:
                    light.setColor(ColorRGBA.Red);
                    //   ln.addControl(new MoveControl(5f));
                    break;
                case 1:
                    light.setColor(ColorRGBA.Yellow);
                    //    ln.addControl(new MoveControl(5f));
                    break;
                case 2:
                    light.setColor(ColorRGBA.Green);
                    //ln.addControl(new MoveControl(-5f));
                    break;
                case 3:
                    light.setColor(ColorRGBA.Orange);
                    //ln.addControl(new MoveControl(-5f));
                    break;
            }
        }
        Geometry b = boxGeo.clone(false);
        cubeNodes.attachChild(b);
        b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
    }
    //        cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
    //        cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
    cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
    cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
    BasicProfilerState profiler = new BasicProfilerState(true);
    profiler.setGraphScale(1000f);
    //  getStateManager().attach(profiler);
    //        guiNode.setCullHint(CullHint.Always);
    flyCam.setDragToRotate(true);
    flyCam.setMoveSpeed(50);
    final MaterialDebugAppState debug = new MaterialDebugAppState();
    stateManager.attach(debug);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggle") && isPressed) {
                if (lm == TechniqueDef.LightMode.SinglePass) {
                    lm = TechniqueDef.LightMode.MultiPass;
                    helloText.setText("(Multi pass)");
                } else {
                    lm = TechniqueDef.LightMode.SinglePass;
                    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
                }
                renderManager.setPreferredLightMode(lm);
                reloadScene(g, boxGeo, cubeNodes);
            }
            if (name.equals("lightsUp") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("lightsDown") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("toggleOnOff") && isPressed) {
                for (final Light light : lightList) {
                    if (light instanceof AmbientLight) {
                        continue;
                    }
                    light.setEnabled(!light.isEnabled());
                }
            }
        }
    }, "toggle", "lightsUp", "lightsDown", "toggleOnOff");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
    SpotLight spot = new SpotLight();
    spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
    spot.setColor(ColorRGBA.Blue.mult(5));
    spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
    spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
    spot.setPosition(new Vector3f(10, 10, 20));
    rootNode.addLight(spot);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, 1));
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    rootNode.addLight(al);
    /**
         * Write text on the screen (HUD)
         */
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);
}
Also used : Quaternion(com.jme3.math.Quaternion) MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) SpotLight(com.jme3.light.SpotLight) BasicProfilerState(com.jme3.app.BasicProfilerState) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) ActionListener(com.jme3.input.controls.ActionListener) BitmapText(com.jme3.font.BitmapText) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) PointLight(com.jme3.light.PointLight) Light(com.jme3.light.Light) AmbientLight(com.jme3.light.AmbientLight) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) LightList(com.jme3.light.LightList) PointLight(com.jme3.light.PointLight) AmbientLight(com.jme3.light.AmbientLight)

Example 73 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class TestPointDirectionalAndSpotLightShadows method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(0.040581334f, 1.7745866f, 6.155161f));
    cam.setRotation(new Quaternion(4.3868728E-5f, 0.9999293f, -0.011230096f, 0.0039059948f));
    Node scene = (Node) assetManager.loadModel("Models/Test/CornellBox.j3o");
    scene.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(scene);
    rootNode.getChild("Cube").setShadowMode(RenderQueue.ShadowMode.Receive);
    lightNode = (Node) rootNode.getChild("Lamp");
    Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setShadowMode(RenderQueue.ShadowMode.Off);
    lightNode.attachChild(lightMdl);
    //lightMdl.setLocalTranslation(lightNode.getLocalTranslation());
    Geometry box = new Geometry("box", new Box(0.2f, 0.2f, 0.2f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    box.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(box);
    box.setLocalTranslation(-1f, 0.5f, -2);
    ((PointLight) scene.getLocalLightList().get(0)).setColor(ColorRGBA.Red);
    plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    plsr.setLight((PointLight) scene.getLocalLightList().get(0));
    plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    plsf.setLight((PointLight) scene.getLocalLightList().get(0));
    plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsf.setEnabled(useFilter);
    //DIRECTIONAL LIGHT
    DirectionalLight directionalLight = new DirectionalLight();
    rootNode.addLight(directionalLight);
    directionalLight.setColor(ColorRGBA.Blue);
    directionalLight.setDirection(new Vector3f(-1f, -.2f, 0f));
    dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE * 2, 4);
    dlsr.setLight(directionalLight);
    dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE * 2, 4);
    dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    dlsf.setLight(directionalLight);
    dlsf.setEnabled(useFilter);
    //SPOT LIGHT
    spotLight = new SpotLight();
    spotLight.setDirection(new Vector3f(1f, -1f, 0f));
    spotLight.setPosition(new Vector3f(-1f, 3f, 0f));
    spotLight.setSpotOuterAngle(0.5f);
    spotLight.setColor(ColorRGBA.Green);
    Sphere sphere = new Sphere(8, 8, .1f);
    Geometry sphereGeometry = new Geometry("Sphere", sphere);
    sphereGeometry.setLocalTranslation(-1f, 3f, 0f);
    sphereGeometry.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"));
    rootNode.attachChild(sphereGeometry);
    rootNode.addLight(spotLight);
    slsr = new SpotLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    slsr.setLight(spotLight);
    slsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    slsf = new SpotLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    slsf.setLight(spotLight);
    slsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    slsf.setEnabled(useFilter);
    if (!useFilter)
        viewPort.addProcessor(slsr);
    if (!useFilter)
        viewPort.addProcessor(plsr);
    if (!useFilter)
        viewPort.addProcessor(dlsr);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(plsf);
    fpp.addFilter(dlsf);
    fpp.addFilter(slsf);
    viewPort.addProcessor(fpp);
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
    ShadowTestUIManager uiManPls = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
    ShadowTestUIManager uiManDls = new ShadowTestUIManager(assetManager, dlsr, dlsf, guiNode, inputManager, viewPort);
    ShadowTestUIManager uiManSls = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
}
Also used : SpotLightShadowFilter(com.jme3.shadow.SpotLightShadowFilter) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) PointLightShadowFilter(com.jme3.shadow.PointLightShadowFilter) Box(com.jme3.scene.shape.Box) PointLightShadowRenderer(com.jme3.shadow.PointLightShadowRenderer) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) DirectionalLightShadowRenderer(com.jme3.shadow.DirectionalLightShadowRenderer) PointLight(com.jme3.light.PointLight)

Example 74 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class TestPssmShadow method loadScene.

public void loadScene() {
    obj = new Spatial[2];
    mat = new Material[2];
    mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat[1].setBoolean("UseMaterialColors", true);
    mat[1].setColor("Ambient", ColorRGBA.White.mult(0.5f));
    mat[1].setColor("Diffuse", ColorRGBA.White.clone());
    obj[0] = new Geometry("sphere", new Sphere(30, 30, 2));
    obj[0].setShadowMode(ShadowMode.CastAndReceive);
    obj[1] = new Geometry("cube", new Box(1.0f, 1.0f, 1.0f));
    obj[1].setShadowMode(ShadowMode.CastAndReceive);
    TangentBinormalGenerator.generate(obj[1]);
    TangentBinormalGenerator.generate(obj[0]);
    for (int i = 0; i < 60; i++) {
        Spatial t = obj[FastMath.nextRandomInt(0, obj.length - 1)].clone(false);
        t.setLocalScale(FastMath.nextRandomFloat() * 10f);
        t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]);
        rootNode.attachChild(t);
        t.setLocalTranslation(FastMath.nextRandomFloat() * 200f, FastMath.nextRandomFloat() * 30f + 20, 30f * (i + 2f));
    }
    Box b = new Box(1000, 2, 1000);
    b.scaleTextureCoordinates(new Vector2f(10, 10));
    ground = new Geometry("soil", b);
    ground.setLocalTranslation(0, 10, 550);
    matGroundU = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matGroundU.setColor("Color", ColorRGBA.Green);
    matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matGroundL.setTexture("DiffuseMap", grass);
    ground.setMaterial(matGroundL);
    ground.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(ground);
    l = new DirectionalLight();
    l.setDirection(new Vector3f(-1, -1, -1));
    rootNode.addLight(l);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.5f));
    rootNode.addLight(al);
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    rootNode.attachChild(sky);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Spatial(com.jme3.scene.Spatial) Vector2f(com.jme3.math.Vector2f) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) AmbientLight(com.jme3.light.AmbientLight)

Example 75 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class TestSpotLight method setupLighting.

public void setupLighting() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    spot = new SpotLight();
    spot.setSpotRange(1000);
    spot.setSpotInnerAngle(5 * FastMath.DEG_TO_RAD);
    spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    spot.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    spot.setDirection(lightTarget.subtract(spot.getPosition()));
    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(2));
//        rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) SpotLight(com.jme3.light.SpotLight) AmbientLight(com.jme3.light.AmbientLight)

Aggregations

DirectionalLight (com.jme3.light.DirectionalLight)104 Vector3f (com.jme3.math.Vector3f)87 Geometry (com.jme3.scene.Geometry)55 Material (com.jme3.material.Material)48 Spatial (com.jme3.scene.Spatial)41 ColorRGBA (com.jme3.math.ColorRGBA)34 Quaternion (com.jme3.math.Quaternion)30 Node (com.jme3.scene.Node)29 Box (com.jme3.scene.shape.Box)27 Sphere (com.jme3.scene.shape.Sphere)26 AmbientLight (com.jme3.light.AmbientLight)25 FilterPostProcessor (com.jme3.post.FilterPostProcessor)24 PointLight (com.jme3.light.PointLight)23 KeyTrigger (com.jme3.input.controls.KeyTrigger)22 ActionListener (com.jme3.input.controls.ActionListener)14 SpotLight (com.jme3.light.SpotLight)14 Texture (com.jme3.texture.Texture)12 AnimControl (com.jme3.animation.AnimControl)9 BulletAppState (com.jme3.bullet.BulletAppState)8 Quad (com.jme3.scene.shape.Quad)8