Search in sources :

Example 71 with Light

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

the class LightProbeBlendingProcessor method computeBlendFactors.

private float computeBlendFactors(List<BlendFactor> blendFactors) {
    float sumBlendFactors = 0;
    for (Spatial scene : viewPort.getScenes()) {
        for (Light light : scene.getWorldLightList()) {
            if (light.getType() == Light.Type.Probe) {
                LightProbe p = (LightProbe) light;
                TempVars vars = TempVars.get();
                boolean intersect = p.intersectsFrustum(viewPort.getCamera(), vars);
                vars.release();
                //check if the probe is inside the camera frustum
                if (intersect) {
                    //is the poi inside the bounds of this probe
                    if (poi.getWorldBound().intersects(p.getBounds())) {
                        //computing the distance as we need it to check if th epoi in in the inner radius and later to compute the weight
                        float outerRadius = ((BoundingSphere) p.getBounds()).getRadius();
                        float innerRadius = outerRadius * 0.5f;
                        float distance = p.getBounds().getCenter().distance(poi.getWorldTranslation());
                        // if the poi in inside the inner range of this probe, then this probe is the only one that matters.
                        if (distance < innerRadius) {
                            blendFactors.clear();
                            blendFactors.add(new BlendFactor(p, 1.0f));
                            return 1.0f;
                        }
                        //else we need to compute the weight of this probe and collect it for blending
                        float ndf = (distance - innerRadius) / (outerRadius - innerRadius);
                        sumBlendFactors += ndf;
                        blendFactors.add(new BlendFactor(p, ndf));
                    }
                }
            }
        }
    }
    return sumBlendFactors;
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Spatial(com.jme3.scene.Spatial) TempVars(com.jme3.util.TempVars)

Example 72 with Light

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

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

the class BasicShadowRenderer method postQueue.

public void postQueue(RenderQueue rq) {
    for (Spatial scene : viewPort.getScenes()) {
        ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), ShadowMode.Receive, lightReceivers);
    }
    // update frustum points based on current camera
    Camera viewCam = viewPort.getCamera();
    ShadowUtil.updateFrustumPoints(viewCam, viewCam.getFrustumNear(), viewCam.getFrustumFar(), 1.0f, points);
    Vector3f frustaCenter = new Vector3f();
    for (Vector3f point : points) {
        frustaCenter.addLocal(point);
    }
    frustaCenter.multLocal(1f / 8f);
    // update light direction
    shadowCam.setProjectionMatrix(null);
    shadowCam.setParallelProjection(true);
    //        shadowCam.setFrustumPerspective(45, 1, 1, 20);
    shadowCam.lookAtDirection(direction, Vector3f.UNIT_Y);
    shadowCam.update();
    shadowCam.setLocation(frustaCenter);
    shadowCam.update();
    shadowCam.updateViewProjection();
    // render shadow casters to shadow map
    ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize);
    if (shadowOccluders.size() == 0) {
        noOccluders = true;
        return;
    } else {
        noOccluders = false;
    }
    Renderer r = renderManager.getRenderer();
    renderManager.setCamera(shadowCam, false);
    renderManager.setForcedMaterial(preshadowMat);
    r.setFrameBuffer(shadowFB);
    r.clearBuffers(true, true, true);
    viewPort.getQueue().renderShadowQueue(shadowOccluders, renderManager, shadowCam, true);
    r.setFrameBuffer(viewPort.getOutputFrameBuffer());
    renderManager.setForcedMaterial(null);
    renderManager.setCamera(viewCam, false);
}
Also used : Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) Renderer(com.jme3.renderer.Renderer) Camera(com.jme3.renderer.Camera)

Example 74 with Light

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

the class ShadowUtil method getGeometriesInLightRadius.

/**
     * Populates the outputGeometryList with the geometry of the
     * inputGeomtryList that are in the radius of a light.
     * The array of camera must be an array of 6 cameras initialized so they represent the light viewspace of a pointlight
     *
     * @param inputGeometryList The list containing all geometry to check
     * against the camera frustum
     * @param cameras the camera array to check geometries against
     * @param outputGeometryList the list of all geometries that are in the
     * camera frustum
     */
public static void getGeometriesInLightRadius(GeometryList inputGeometryList, Camera[] cameras, GeometryList outputGeometryList) {
    for (int i = 0; i < inputGeometryList.size(); i++) {
        Geometry g = inputGeometryList.get(i);
        boolean inFrustum = false;
        for (int j = 0; j < cameras.length && inFrustum == false; j++) {
            Camera camera = cameras[j];
            int planeState = camera.getPlaneState();
            camera.setPlaneState(0);
            inFrustum = camera.contains(g.getWorldBound()) != Camera.FrustumIntersect.Outside;
            camera.setPlaneState(planeState);
        }
        if (inFrustum) {
            outputGeometryList.add(g);
        }
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Camera(com.jme3.renderer.Camera)

Example 75 with Light

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

the class LightControl method lightToSpatial.

private void lightToSpatial(Light light) {
    TempVars vars = TempVars.get();
    if (light instanceof PointLight) {
        PointLight pLight = (PointLight) light;
        Vector3f vecDiff = vars.vect1.set(pLight.getPosition()).subtractLocal(spatial.getWorldTranslation());
        spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
    }
    if (light instanceof DirectionalLight) {
        DirectionalLight dLight = (DirectionalLight) light;
        vars.vect1.set(dLight.getDirection()).multLocal(-1.0f);
        Vector3f vecDiff = vars.vect1.subtractLocal(spatial.getWorldTranslation());
        spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
    }
    vars.release();
//TODO add code for Spot light here when it's done
}
Also used : Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) TempVars(com.jme3.util.TempVars) PointLight(com.jme3.light.PointLight)

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