Search in sources :

Example 6 with LightList

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

the class StaticPassLightingLogic method render.

@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    Renderer renderer = renderManager.getRenderer();
    Matrix4f viewMatrix = renderManager.getCurrentCamera().getViewMatrix();
    updateLightListUniforms(viewMatrix, shader, lights);
    renderer.setShader(shader);
    renderMeshFromGeometry(renderer, geometry);
}
Also used : Matrix4f(com.jme3.math.Matrix4f) Renderer(com.jme3.renderer.Renderer)

Example 7 with LightList

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

Example 8 with LightList

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

the class PoiLightProbeLightFilter 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 (light.getType() == Light.Type.Probe) {
                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;
                    }
                }
            }
            filteredLightList.add(light);
        }
        processor.populateProbe(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)

Example 9 with LightList

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

the class LightFilterTest method setUp.

@Before
public void setUp() {
    filter = new DefaultLightFilter();
    cam = new Camera(512, 512);
    cam.setFrustumPerspective(45, 1, 1, 1000);
    cam.setLocation(Vector3f.ZERO);
    cam.lookAtDirection(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
    filter.setCamera(cam);
    Box box = new Box(1, 1, 1);
    geom = new Geometry("geom", box);
    geom.setLocalTranslation(0, 0, 10);
    geom.updateGeometricState();
    list = new LightList(geom);
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Camera(com.jme3.renderer.Camera) Before(org.junit.Before)

Example 10 with LightList

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

Aggregations

DirectionalLight (com.jme3.light.DirectionalLight)5 PointLight (com.jme3.light.PointLight)5 SpotLight (com.jme3.light.SpotLight)5 Renderer (com.jme3.renderer.Renderer)5 TempVars (com.jme3.util.TempVars)5 Light (com.jme3.light.Light)4 ColorRGBA (com.jme3.math.ColorRGBA)4 Vector3f (com.jme3.math.Vector3f)4 Geometry (com.jme3.scene.Geometry)4 BoundingSphere (com.jme3.bounding.BoundingSphere)3 Uniform (com.jme3.shader.Uniform)3 BoundingBox (com.jme3.bounding.BoundingBox)2 BoundingVolume (com.jme3.bounding.BoundingVolume)2 AmbientLight (com.jme3.light.AmbientLight)2 LightList (com.jme3.light.LightList)2 Material (com.jme3.material.Material)2 TechniqueDefLogic (com.jme3.material.logic.TechniqueDefLogic)2 Quaternion (com.jme3.math.Quaternion)2 Vector4f (com.jme3.math.Vector4f)2 Mesh (com.jme3.scene.Mesh)2