Search in sources :

Example 31 with PointLight

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

the class TestSpotLightShadows method setupLighting.

public void setupLighting() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    rootNode.setShadowMode(ShadowMode.CastAndReceive);
    spot = new SpotLight();
    spot.setSpotRange(1000);
    spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
    spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
    spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
    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(0.7f));
    //        rootNode.addLight(dl);
    final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
    slsr.setLight(spot);
    slsr.setShadowIntensity(0.5f);
    slsr.setShadowZExtend(100);
    slsr.setShadowZFadeLength(5);
    slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    viewPort.addProcessor(slsr);
    SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
    slsf.setLight(spot);
    slsf.setShadowIntensity(0.5f);
    slsf.setShadowZExtend(100);
    slsf.setShadowZFadeLength(5);
    slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    slsf.setEnabled(false);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(slsf);
    viewPort.addProcessor(fpp);
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("stop") && isPressed) {
                stop = !stop;
                //   slsr.displayFrustum();
                System.out.println("pos : " + spot.getPosition());
                System.out.println("dir : " + spot.getDirection());
            }
        }
    }, "stop");
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_1));
    flyCam.setDragToRotate(true);
}
Also used : SpotLightShadowFilter(com.jme3.shadow.SpotLightShadowFilter) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ActionListener(com.jme3.input.controls.ActionListener) AmbientLight(com.jme3.light.AmbientLight)

Example 32 with PointLight

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

the class TestTangentCube method simpleInitApp.

@Override
public void simpleInitApp() {
    Box aBox = new Box(1, 1, 1);
    Geometry aGeometry = new Geometry("Box", aBox);
    TangentBinormalGenerator.generate(aBox);
    Material aMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    aMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    aMaterial.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall_normal.jpg"));
    aMaterial.setBoolean("UseMaterialColors", false);
    aMaterial.setColor("Diffuse", ColorRGBA.White);
    aMaterial.setColor("Specular", ColorRGBA.White);
    aMaterial.setFloat("Shininess", 64f);
    aGeometry.setMaterial(aMaterial);
    // Rotate 45 degrees to see multiple faces
    aGeometry.rotate(FastMath.QUARTER_PI, FastMath.QUARTER_PI, 0.0f);
    rootNode.attachChild(aGeometry);
    /**
         * Must add a light to make the lit object visible!
         */
    PointLight aLight = new PointLight();
    aLight.setPosition(new Vector3f(0, 3, 3));
    aLight.setColor(ColorRGBA.Red);
    rootNode.addLight(aLight);
    //
    //        AmbientLight bLight = new AmbientLight();
    //        bLight.setColor(ColorRGBA.Gray);
    //        rootNode.addLight(bLight);
    ChaseCameraAppState chaser = new ChaseCameraAppState();
    chaser.setTarget(aGeometry);
    getStateManager().attach(chaser);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) PointLight(com.jme3.light.PointLight) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState)

Example 33 with PointLight

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

the class TestTangentGenBadModels method simpleInitApp.

@Override
public void simpleInitApp() {
    //        assetManager.registerLocator("http://jme-glsl-shaders.googlecode.com/hg/assets/Models/LightBlow/", UrlLocator.class);
    //        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/", UrlLocator.class);
    final Spatial badModel = assetManager.loadModel("Models/TangentBugs/test.blend");
    //        badModel.setLocalScale(1f);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png"));
    //        Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
    badModel.setMaterial(mat);
    rootNode.attachChild(badModel);
    // TODO: For some reason blender loader fails to load this.
    // need to check it
    //        Spatial model = assetManager.loadModel("test.blend");
    //        rootNode.attachChild(model);
    final Node debugTangents = new Node("debug tangents");
    debugTangents.setCullHint(CullHint.Always);
    rootNode.attachChild(debugTangents);
    final Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    badModel.depthFirstTraversal(new SceneGraphVisitorAdapter() {

        @Override
        public void visit(Geometry g) {
            Mesh m = g.getMesh();
            Material mat = g.getMaterial();
            //                if (mat.getParam("DiffuseMap") != null){
            //                    mat.setTexture("DiffuseMap", null);
            //                }
            TangentBinormalGenerator.generate(m);
            Geometry debug = new Geometry("debug tangents geom", TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f));
            debug.setMaterial(debugMat);
            debug.setCullHint(Spatial.CullHint.Never);
            debug.setLocalTransform(g.getWorldTransform());
            debugTangents.attachChild(debug);
        }
    });
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.8f, -0.6f, -0.08f).normalizeLocal());
    dl.setColor(new ColorRGBA(1, 1, 1, 1));
    rootNode.addLight(dl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.getMesh().setStatic();
    rootNode.attachChild(lightMdl);
    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    //        rootNode.addLight(pl);
    BitmapText info = new BitmapText(guiFont);
    info.setText("Press SPACE to switch between lighting and tangent display");
    info.setQueueBucket(Bucket.Gui);
    info.move(0, settings.getHeight() - info.getLineHeight(), 0);
    rootNode.attachChild(info);
    inputManager.addMapping("space", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(new ActionListener() {

        private boolean isLit = true;

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed)
                return;
            Material mat;
            if (isLit) {
                mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
                debugTangents.setCullHint(CullHint.Inherit);
            } else {
                mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
                mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png"));
                debugTangents.setCullHint(CullHint.Always);
            }
            isLit = !isLit;
            badModel.setMaterial(mat);
        }
    }, "space");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) BitmapText(com.jme3.font.BitmapText) ActionListener(com.jme3.input.controls.ActionListener) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight)

Example 34 with PointLight

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

the class TestTangentGenBadUV method simpleInitApp.

@Override
public void simpleInitApp() {
    Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    if (teapot instanceof Geometry) {
        Geometry g = (Geometry) teapot;
        TangentBinormalGenerator.generate(g.getMesh());
    } else {
        throw new RuntimeException();
    }
    teapot.setLocalScale(2f);
    Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
    teapot.setMaterial(mat);
    rootNode.attachChild(teapot);
    Geometry debug = new Geometry("Debug Teapot", TangentBinormalGenerator.genTbnLines(((Geometry) teapot).getMesh(), 0.03f));
    Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    debug.setMaterial(debugMat);
    debug.setCullHint(Spatial.CullHint.Never);
    debug.getLocalTranslation().set(teapot.getLocalTranslation());
    debug.getLocalScale().set(teapot.getLocalScale());
    rootNode.attachChild(debug);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -1, -1).normalizeLocal());
    dl.setColor(ColorRGBA.White);
    rootNode.addLight(dl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.getMesh().setStatic();
    rootNode.attachChild(lightMdl);
    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    //pl.setRadius(3f);
    rootNode.addLight(pl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) PointLight(com.jme3.light.PointLight)

Example 35 with PointLight

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

the class TestTwoSideLighting method simpleInitApp.

@Override
public void simpleInitApp() {
    // Two-sided lighting requires single pass.
    renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
    renderManager.setSinglePassLightBatchSize(4);
    cam.setLocation(new Vector3f(5.936224f, 3.3759952f, -3.3202777f));
    cam.setRotation(new Quaternion(0.16265652f, -0.4811838f, 0.09137692f, 0.8565368f));
    Geometry quadGeom = new Geometry("quad", new Quad(1, 1));
    quadGeom.move(1, 0, 0);
    Material mat1 = assetManager.loadMaterial("Textures/BumpMapTest/SimpleBump.j3m");
    // Display both front and back faces.
    mat1.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
    quadGeom.setMaterial(mat1);
    // SimpleBump material requires tangents.
    TangentBinormalGenerator.generate(quadGeom);
    rootNode.attachChild(quadGeom);
    Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.move(-1, 0, 0);
    teapot.setLocalScale(2f);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat2.setFloat("Shininess", 25);
    mat2.setBoolean("UseMaterialColors", true);
    mat2.setColor("Ambient", ColorRGBA.Black);
    mat2.setColor("Diffuse", ColorRGBA.Gray);
    mat2.setColor("Specular", ColorRGBA.Gray);
    // Only display backfaces.
    mat2.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Front);
    teapot.setMaterial(mat2);
    rootNode.attachChild(teapot);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.getMesh().setStatic();
    rootNode.attachChild(lightMdl);
    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    pl.setRadius(4f);
    rootNode.addLight(pl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) PointLight(com.jme3.light.PointLight)

Aggregations

PointLight (com.jme3.light.PointLight)30 Vector3f (com.jme3.math.Vector3f)28 Geometry (com.jme3.scene.Geometry)22 DirectionalLight (com.jme3.light.DirectionalLight)21 Sphere (com.jme3.scene.shape.Sphere)18 SpotLight (com.jme3.light.SpotLight)14 Material (com.jme3.material.Material)12 ColorRGBA (com.jme3.math.ColorRGBA)12 Quaternion (com.jme3.math.Quaternion)9 AmbientLight (com.jme3.light.AmbientLight)8 Node (com.jme3.scene.Node)8 Light (com.jme3.light.Light)5 Spatial (com.jme3.scene.Spatial)5 TempVars (com.jme3.util.TempVars)5 FilterPostProcessor (com.jme3.post.FilterPostProcessor)4 Box (com.jme3.scene.shape.Box)4 SpotLightShadowRenderer (com.jme3.shadow.SpotLightShadowRenderer)4 ActionListener (com.jme3.input.controls.ActionListener)3 KeyTrigger (com.jme3.input.controls.KeyTrigger)3 Uniform (com.jme3.shader.Uniform)3