Search in sources :

Example 21 with AmbientLight

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

the class LightSortTest method testSimpleSort.

@Test
public void testSimpleSort() {
    Geometry g = new Geometry("test", new Mesh());
    LightList list = new LightList(g);
    list.add(new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X));
    list.add(new PointLight(Vector3f.UNIT_X));
    list.add(new DirectionalLight(Vector3f.UNIT_X));
    list.add(new AmbientLight());
    list.sort(true);
    // Ambients always first
    assert list.get(0) instanceof AmbientLight;
    // .. then directionals
    assert list.get(1) instanceof DirectionalLight;
    // Spot is 0 units away from geom
    assert list.get(2) instanceof SpotLight;
    // .. and point is 1 unit away.
    assert list.get(3) instanceof PointLight;
}
Also used : Geometry(com.jme3.scene.Geometry) Mesh(com.jme3.scene.Mesh) Test(org.junit.Test)

Example 22 with AmbientLight

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

the class PhysicsTestHelper method createPhysicsTestWorld.

/**
     * creates a simple physics test world with a floor, an obstacle and some test boxes
     * @param rootNode
     * @param assetManager
     * @param space
     */
public static void createPhysicsTestWorld(Node rootNode, AssetManager assetManager, PhysicsSpace space) {
    AmbientLight light = new AmbientLight();
    light.setColor(ColorRGBA.LightGray);
    rootNode.addLight(light);
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Box floorBox = new Box(140, 0.25f, 140);
    Geometry floorGeometry = new Geometry("Floor", floorBox);
    floorGeometry.setMaterial(material);
    floorGeometry.setLocalTranslation(0, -5, 0);
    //        Plane plane = new Plane();
    //        plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
    //        floorGeometry.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
    floorGeometry.addControl(new RigidBodyControl(0));
    rootNode.attachChild(floorGeometry);
    space.add(floorGeometry);
    //movable boxes
    for (int i = 0; i < 12; i++) {
        Box box = new Box(0.25f, 0.25f, 0.25f);
        Geometry boxGeometry = new Geometry("Box", box);
        boxGeometry.setMaterial(material);
        boxGeometry.setLocalTranslation(i, 5, -3);
        //RigidBodyControl automatically uses box collision shapes when attached to single geometry with box mesh
        boxGeometry.addControl(new RigidBodyControl(2));
        rootNode.attachChild(boxGeometry);
        space.add(boxGeometry);
    }
    //immovable sphere with mesh collision shape
    Sphere sphere = new Sphere(8, 8, 1);
    Geometry sphereGeometry = new Geometry("Sphere", sphere);
    sphereGeometry.setMaterial(material);
    sphereGeometry.setLocalTranslation(4, -4, 2);
    sphereGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(sphere), 0));
    rootNode.attachChild(sphereGeometry);
    space.add(sphereGeometry);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) MeshCollisionShape(com.jme3.bullet.collision.shapes.MeshCollisionShape) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) AmbientLight(com.jme3.light.AmbientLight)

Example 23 with AmbientLight

use of com.jme3.light.AmbientLight 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 24 with AmbientLight

use of com.jme3.light.AmbientLight 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 25 with AmbientLight

use of com.jme3.light.AmbientLight 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

AmbientLight (com.jme3.light.AmbientLight)35 DirectionalLight (com.jme3.light.DirectionalLight)24 Vector3f (com.jme3.math.Vector3f)24 Geometry (com.jme3.scene.Geometry)24 Material (com.jme3.material.Material)16 Box (com.jme3.scene.shape.Box)13 Node (com.jme3.scene.Node)12 Spatial (com.jme3.scene.Spatial)12 Sphere (com.jme3.scene.shape.Sphere)12 ColorRGBA (com.jme3.math.ColorRGBA)11 Quaternion (com.jme3.math.Quaternion)9 SpotLight (com.jme3.light.SpotLight)8 ActionListener (com.jme3.input.controls.ActionListener)7 KeyTrigger (com.jme3.input.controls.KeyTrigger)7 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 PointLight (com.jme3.light.PointLight)6 Texture (com.jme3.texture.Texture)6 Vector2f (com.jme3.math.Vector2f)5 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 SSAOFilter (com.jme3.post.ssao.SSAOFilter)3