Search in sources :

Example 61 with Light

use of com.jme3.light.Light 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 62 with Light

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

Example 63 with Light

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

the class LightsDebugState method update.

@Override
public void update(float tpf) {
    for (Light light : scene.getWorldLightList()) {
        switch(light.getType()) {
            case Probe:
                LightProbe probe = (LightProbe) light;
                probes.add(probe);
                Node n = probeMapping.get(probe);
                if (n == null) {
                    n = new Node("DebugProbe");
                    n.attachChild(debugGeom.clone(true));
                    n.attachChild(debugBounds.clone(false));
                    debugNode.attachChild(n);
                    probeMapping.put(probe, n);
                }
                Geometry probeGeom = ((Geometry) n.getChild(0));
                Material m = probeGeom.getMaterial();
                probeGeom.setLocalScale(probeScale);
                if (probe.isReady()) {
                    if (debugMode == DebugMode.IrradianceMap) {
                        m.setTexture("CubeMap", probe.getIrradianceMap());
                    } else {
                        m.setTexture("CubeMap", probe.getPrefilteredEnvMap());
                    }
                }
                n.setLocalTranslation(probe.getPosition());
                n.getChild(1).setLocalScale(((BoundingSphere) probe.getBounds()).getRadius());
                break;
            default:
                break;
        }
    }
    debugNode.updateLogicalState(tpf);
    debugNode.updateGeometricState();
    cleanProbes();
}
Also used : Geometry(com.jme3.scene.Geometry) LightProbe(com.jme3.light.LightProbe) Light(com.jme3.light.Light) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 64 with Light

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

the class SpotLight method intersectsFrustum.

@Override
public boolean intersectsFrustum(Camera cam, TempVars vars) {
    if (spotRange == 0) {
        // The algorithm below does not support infinite spot range.
        return true;
    }
    Vector3f farPoint = vars.vect1.set(position).addLocal(vars.vect2.set(direction).multLocal(spotRange));
    for (int i = 5; i >= 0; i--) {
        //check origin against the plane
        Plane plane = cam.getWorldPlane(i);
        float dot = plane.pseudoDistance(position);
        if (dot < 0) {
            // outside, check the far point against the plane   
            dot = plane.pseudoDistance(farPoint);
            if (dot < 0) {
                // outside, check the projection of the far point along the normal of the plane to the base disc perimeter of the cone
                //computing the radius of the base disc
                float farRadius = (spotRange / outerAngleCos) * outerAngleSin;
                //computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector
                Vector3f perpDirection = vars.vect2.set(direction).crossLocal(plane.getNormal()).normalizeLocal().crossLocal(direction);
                //projecting the far point on the base disc perimeter
                Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius));
                //checking against the plane
                dot = plane.pseudoDistance(projectedPoint);
                if (dot < 0) {
                    // Outside, the light can be culled
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Plane(com.jme3.math.Plane) Vector3f(com.jme3.math.Vector3f)

Example 65 with Light

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

the class DefaultLightFilter method filterLights.

@Override
public void filterLights(Geometry geometry, LightList filteredLightList) {
    TempVars vars = TempVars.get();
    try {
        LightList worldLights = geometry.getWorldLightList();
        for (int i = 0; i < worldLights.size(); i++) {
            Light light = worldLights.get(i);
            // If this light is not enabled it will be ignored.
            if (!light.isEnabled()) {
                continue;
            }
            if (light.frustumCheckNeeded) {
                processedLights.add(light);
                light.frustumCheckNeeded = false;
                light.intersectsFrustum = light.intersectsFrustum(camera, vars);
            }
            if (!light.intersectsFrustum) {
                continue;
            }
            BoundingVolume bv = geometry.getWorldBound();
            if (bv instanceof BoundingBox) {
                if (!light.intersectsBox((BoundingBox) bv, vars)) {
                    continue;
                }
            } else if (bv instanceof BoundingSphere) {
                if (!Float.isInfinite(((BoundingSphere) bv).getRadius())) {
                    if (!light.intersectsSphere((BoundingSphere) bv, vars)) {
                        continue;
                    }
                }
            }
            if (light.getType() == Light.Type.Probe) {
                probeBlendStrat.registerProbe((LightProbe) light);
            } else {
                filteredLightList.add(light);
            }
        }
        probeBlendStrat.populateProbes(geometry, filteredLightList);
    } finally {
        vars.release();
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

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