Search in sources :

Example 31 with Light

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

the class TestBumpModel method simpleInitApp.

@Override
public void simpleInitApp() {
    Spatial signpost = (Spatial) assetManager.loadAsset(new OgreMeshKey("Models/Sign Post/Sign Post.mesh.xml"));
    signpost.setMaterial((Material) assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m"));
    TangentBinormalGenerator.generate(signpost);
    rootNode.attachChild(signpost);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial((Material) assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(lightMdl);
    // flourescent main light
    pl = new PointLight();
    pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f));
    rootNode.addLight(pl);
    // sunset light
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f));
    rootNode.addLight(dl);
    // skylight
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.6f, -1, -0.6f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.10f, 0.22f, 0.44f, 1.0f));
    rootNode.addLight(dl);
    // white ambient light
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
    rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) OgreMeshKey(com.jme3.scene.plugins.ogre.OgreMeshKey) PointLight(com.jme3.light.PointLight)

Example 32 with Light

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

the class TestLightRadius method simpleInitApp.

@Override
public void simpleInitApp() {
    Torus torus = new Torus(10, 6, 1, 3);
    //        Torus torus = new Torus(50, 30, 1, 3);
    Geometry g = new Geometry("Torus Geom", torus);
    g.rotate(-FastMath.HALF_PI, 0, 0);
    g.center();
    //        g.move(0, 1, 0);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 32f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Black);
    mat.setColor("Diffuse", ColorRGBA.White);
    mat.setColor("Specular", ColorRGBA.White);
    //        mat.setBoolean("VertexLighting", true);
    //        mat.setBoolean("LowQuality", true);
    g.setMaterial(mat);
    rootNode.attachChild(g);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(lightMdl);
    pl = new PointLight();
    pl.setColor(ColorRGBA.Green);
    pl.setRadius(4f);
    rootNode.addLight(pl);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.Red);
    dl.setDirection(new Vector3f(0, 1, 0));
    rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Torus(com.jme3.scene.shape.Torus) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) PointLight(com.jme3.light.PointLight)

Example 33 with Light

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

the class TestPointLightShadows 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));
    al = new AmbientLight(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    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);
    plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    plsr.setLight((PointLight) scene.getLocalLightList().get(0));
    plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsr.setShadowZExtend(15);
    plsr.setShadowZFadeLength(5);
    plsr.setShadowIntensity(0.9f);
    // plsr.setFlushQueues(false);
    //plsr.displayFrustum();
    plsr.displayDebug();
    viewPort.addProcessor(plsr);
    plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    plsf.setLight((PointLight) scene.getLocalLightList().get(0));
    plsf.setShadowZExtend(15);
    plsf.setShadowZFadeLength(5);
    plsf.setShadowIntensity(0.8f);
    plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsf.setEnabled(false);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(plsf);
    viewPort.addProcessor(fpp);
    inputManager.addListener(this, "ShadowUp", "ShadowDown");
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) 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) AmbientLight(com.jme3.light.AmbientLight)

Example 34 with Light

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

the class HelloMaterial method simpleInitApp.

@Override
public void simpleInitApp() {
    /** A simple textured cube -- in good MIP map quality. */
    Box cube1Mesh = new Box(1f, 1f, 1f);
    Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
    cube1Geo.setLocalTranslation(new Vector3f(-3f, 1.1f, 0f));
    Material cube1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture cube1Tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    cube1Mat.setTexture("ColorMap", cube1Tex);
    cube1Geo.setMaterial(cube1Mat);
    rootNode.attachChild(cube1Geo);
    /** A translucent/transparent texture, similar to a window frame. */
    Box cube2Mesh = new Box(1f, 1f, 0.01f);
    Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
    Material cube2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    cube2Mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
    // activate transparency
    cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    cube2Geo.setQueueBucket(Bucket.Transparent);
    cube2Geo.setMaterial(cube2Mat);
    rootNode.attachChild(cube2Geo);
    /** A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
    Sphere sphereMesh = new Sphere(32, 32, 2f);
    Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
    // better quality on spheres
    sphereMesh.setTextureMode(Sphere.TextureMode.Projected);
    // for lighting effect
    TangentBinormalGenerator.generate(sphereMesh);
    Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
    sphereMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
    sphereMat.setBoolean("UseMaterialColors", true);
    sphereMat.setColor("Diffuse", ColorRGBA.White);
    sphereMat.setColor("Specular", ColorRGBA.White);
    // [0,128]
    sphereMat.setFloat("Shininess", 64f);
    sphereGeo.setMaterial(sphereMat);
    //sphereGeo.setMaterial((Material) assetManager.loadMaterial("Materials/MyCustomMaterial.j3m"));
    // Move it a bit
    sphereGeo.setLocalTranslation(0, 2, -2);
    // Rotate it a bit
    sphereGeo.rotate(1.6f, 0, 0);
    rootNode.attachChild(sphereGeo);
    /** Must add a light to make the lit object visible! */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(1, 0, -2).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 35 with Light

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

the class TestTangentSpace method simpleInitApp.

@Override
public void simpleInitApp() {
    renderManager.setSinglePassLightBatchSize(2);
    renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
    initView();
    Spatial s = assetManager.loadModel("Models/Test/BasicCubeLow.obj");
    rootNode.attachChild(s);
    Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    m.setTexture("NormalMap", assetManager.loadTexture("Models/Test/Normal_pixel.png"));
    Geometry g = (Geometry) s;
    Geometry g2 = (Geometry) g.deepClone();
    g2.move(5, 0, 0);
    g.getParent().attachChild(g2);
    g.setMaterial(m);
    g2.setMaterial(m);
    //Regular tangent generation (left geom)
    TangentBinormalGenerator.generate(g2.getMesh(), true);
    //MikkTSPace Tangent generation (right geom)        
    MikktspaceTangentGenerator.generate(g);
    createDebugTangents(g2);
    createDebugTangents(g);
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggleDebug") && isPressed) {
                if (debugNode.getParent() == null) {
                    rootNode.attachChild(debugNode);
                } else {
                    debugNode.removeFromParent();
                }
            }
        }
    }, "toggleDebug");
    inputManager.addMapping("toggleDebug", new KeyTrigger(KeyInput.KEY_SPACE));
    DirectionalLight dl = new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) KeyTrigger(com.jme3.input.controls.KeyTrigger) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Aggregations

Vector3f (com.jme3.math.Vector3f)64 Material (com.jme3.material.Material)61 DirectionalLight (com.jme3.light.DirectionalLight)55 Geometry (com.jme3.scene.Geometry)52 PointLight (com.jme3.light.PointLight)27 Spatial (com.jme3.scene.Spatial)27 Box (com.jme3.scene.shape.Box)26 Sphere (com.jme3.scene.shape.Sphere)26 ColorRGBA (com.jme3.math.ColorRGBA)24 Quaternion (com.jme3.math.Quaternion)21 Node (com.jme3.scene.Node)21 AmbientLight (com.jme3.light.AmbientLight)20 Texture (com.jme3.texture.Texture)18 SpotLight (com.jme3.light.SpotLight)16 FilterPostProcessor (com.jme3.post.FilterPostProcessor)15 KeyTrigger (com.jme3.input.controls.KeyTrigger)11 Test (org.junit.Test)11 TempVars (com.jme3.util.TempVars)10 Light (com.jme3.light.Light)9 Camera (com.jme3.renderer.Camera)9