Search in sources :

Example 51 with DirectionalLight

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

the class TestBlendEquations method simpleInitApp.

public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teaGeom.scale(6);
    teaGeom.getMaterial().getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Add);
    teaGeom.move(0, -2f, 0);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.Red);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(0.5f, 0f, 1f, 0.3f));
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Color);
    mat.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Subtract);
    Geometry geo = new Geometry("BottomLeft", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(mat);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(0, 0, 1);
    guiNode.attachChild(geo);
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.ReverseSubtract);
    m.setColor("Color", new ColorRGBA(0.0f, 1f, 1.f, 1f));
    m.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.AlphaAdditive);
    geo = new Geometry("BottomRight", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(m);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(guiViewPort.getCamera().getWidth() / 2, 0, 1);
    guiNode.attachChild(geo);
    m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Min);
    m.setColor("Color", new ColorRGBA(0.3f, 0f, 0.1f, 0.3f));
    m.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Additive);
    geo = new Geometry("TopRight", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(m);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2, 1);
    guiNode.attachChild(geo);
    geo = new Geometry("OverTeaPot", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(mat);
    geo.setQueueBucket(RenderQueue.Bucket.Transparent);
    geo.setLocalTranslation(0, -100, 5);
    rootNode.attachChild(geo);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material)

Example 52 with DirectionalLight

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

the class TestParallelProjection method simpleInitApp.

public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    // Setup first view
    cam.setParallelProjection(true);
    float aspect = (float) cam.getWidth() / cam.getHeight();
    cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize);
    inputManager.addListener(this, "Size+", "Size-");
    inputManager.addMapping("Size+", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Size-", new KeyTrigger(KeyInput.KEY_S));
}
Also used : Geometry(com.jme3.scene.Geometry) DirectionalLight(com.jme3.light.DirectionalLight) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 53 with DirectionalLight

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

the class TestPostWaterLake method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
    //  cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));
    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    File file = new File("wildhouse.zip");
    if (file.exists()) {
        useHttp = false;
    }
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");
    rootNode.attachChild(scene);
    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    final WaterFilter water = new WaterFilter(rootNode, lightDir);
    water.setWaterHeight(-20);
    water.setUseFoam(false);
    water.setUseRipples(false);
    water.setDeepWaterColor(ColorRGBA.Brown);
    water.setWaterColor(ColorRGBA.Brown.mult(2.0f));
    water.setWaterTransparency(0.2f);
    water.setMaxAmplitude(0.3f);
    water.setWaveScale(0.008f);
    water.setSpeed(0.7f);
    water.setShoreHardness(1.0f);
    water.setRefractionConstant(0.2f);
    water.setShininess(0.3f);
    water.setSunScale(1.0f);
    water.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f));
    fpp.addFilter(water);
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (water.isUseHQShoreline()) {
                    water.setUseHQShoreline(false);
                } else {
                    water.setUseHQShoreline(true);
                }
            }
        }
    }, "HQ");
    inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE));
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WaterFilter(com.jme3.water.WaterFilter) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) File(java.io.File)

Example 54 with DirectionalLight

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

the class TerrainTestModifyHeight method simpleInitApp.

@Override
public void simpleInitApp() {
    loadHintText();
    initCrossHairs();
    setupKeys();
    createMarker();
    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    createTerrain();
    //createTerrainGrid();
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);
    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);
    cam.setLocation(new Vector3f(0, 256, 0));
    cam.lookAtDirection(new Vector3f(0, -1f, 0).normalizeLocal(), Vector3f.UNIT_X);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) AmbientLight(com.jme3.light.AmbientLight)

Example 55 with DirectionalLight

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

the class TerrainTestReadWrite method createMap.

private void createMap() {
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    // ALPHA map (for splat textures)
    matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    // HEIGHTMAP image (for the terrain heightmap)
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap", grass);
    matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_1", dirt);
    matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_2", rock);
    matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
    Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMap0.setWrap(WrapMode.Repeat);
    Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMap1.setWrap(WrapMode.Repeat);
    Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMap2.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("NormalMap", normalMap0);
    matTerrain.setTexture("NormalMap_1", normalMap2);
    matTerrain.setTexture("NormalMap_2", normalMap2);
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    // CREATE HEIGHTMAP
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (new File("terrainsave.jme").exists()) {
        loadTerrain();
    } else {
        // create the terrain as normal, and give it a control for LOD management
        //, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
        TerrainQuad terrainQuad = new TerrainQuad("terrain", 65, 129, heightmap.getHeightMap());
        TerrainLodControl control = new TerrainLodControl(terrainQuad, getCamera());
        // patch size, and a multiplier
        control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
        terrainQuad.addControl(control);
        terrainQuad.setMaterial(matTerrain);
        terrainQuad.setLocalTranslation(0, -100, 0);
        terrainQuad.setLocalScale(4f, 0.25f, 4f);
        rootNode.attachChild(terrainQuad);
        this.terrain = terrainQuad;
    }
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

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