Search in sources :

Example 11 with GeometryList

use of com.jme3.renderer.queue.GeometryList 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 12 with GeometryList

use of com.jme3.renderer.queue.GeometryList in project jmonkeyengine by jMonkeyEngine.

the class ShadowUtil method computeUnionBound.

/**
     * Compute bounds of a geomList
     * @param list
     * @param mat
     * @return
     */
public static BoundingBox computeUnionBound(GeometryList list, Matrix4f mat) {
    BoundingBox bbox = new BoundingBox();
    TempVars tempv = TempVars.get();
    for (int i = 0; i < list.size(); i++) {
        BoundingVolume vol = list.get(i).getWorldBound();
        BoundingVolume store = vol.transform(mat, tempv.bbox);
        //Nehon : prevent NaN and infinity values to screw the final bounding box
        if (!Float.isNaN(store.getCenter().x) && !Float.isInfinite(store.getCenter().x)) {
            bbox.mergeLocal(store);
        }
    }
    tempv.release();
    return bbox;
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

Example 13 with GeometryList

use of com.jme3.renderer.queue.GeometryList in project jmonkeyengine by jMonkeyEngine.

the class ShadowUtil method computeUnionBound.

/**
     * Compute bounds of a geomList
     * @param list
     * @param transform
     * @return
     */
public static BoundingBox computeUnionBound(GeometryList list, Transform transform) {
    BoundingBox bbox = new BoundingBox();
    TempVars tempv = TempVars.get();
    for (int i = 0; i < list.size(); i++) {
        BoundingVolume vol = list.get(i).getWorldBound();
        BoundingVolume newVol = vol.transform(transform, tempv.bbox);
        //Nehon : prevent NaN and infinity values to screw the final bounding box
        if (!Float.isNaN(newVol.getCenter().x) && !Float.isInfinite(newVol.getCenter().x)) {
            bbox.mergeLocal(newVol);
        }
    }
    tempv.release();
    return bbox;
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

Example 14 with GeometryList

use of com.jme3.renderer.queue.GeometryList in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method setMatParams.

private void setMatParams(GeometryList l) {
    //iteration throught all the geometries of the list to gather the materials
    buildMatCache(l);
    //iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {
        mat.setFloat("ShadowMapSize", shadowMapSize);
        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setMatrix4(lightViewStringCache[j], lightViewProjectionsMatrices[j]);
        }
        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setTexture(shadowMapStringCache[j], shadowMaps[j]);
        }
        mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware);
        mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue());
        mat.setFloat("PCFEdge", edgesThickness);
        mat.setFloat("ShadowIntensity", shadowIntensity);
        if (fadeInfo != null) {
            mat.setVector2("FadeInfo", fadeInfo);
        }
        if (renderBackFacesShadows != null) {
            mat.setBoolean("BackfaceShadows", renderBackFacesShadows);
        }
        setMaterialParameters(mat);
    }
    //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
    if (needsfallBackMaterial) {
        setPostShadowParams();
    }
}
Also used : Material(com.jme3.material.Material)

Example 15 with GeometryList

use of com.jme3.renderer.queue.GeometryList in project jmonkeyengine by jMonkeyEngine.

the class DirectionalLightShadowRendererVR method getOccludersToRender.

@Override
protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) {
    // update frustum points based on current camera and split
    ShadowUtil.updateFrustumPoints(viewPort.getCamera(), splitsArray[shadowMapIndex], splitsArray[shadowMapIndex + 1], 1.0f, points);
    //Updating shadow cam with curent split frustra
    if (lightReceivers.size() == 0) {
        for (Spatial scene : viewPort.getScenes()) {
            ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), RenderQueue.ShadowMode.Receive, lightReceivers);
        }
    }
    ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, shadowMapOccluders, stabilize ? shadowMapSize : 0);
    return shadowMapOccluders;
}
Also used : Spatial(com.jme3.scene.Spatial)

Aggregations

Geometry (com.jme3.scene.Geometry)6 Spatial (com.jme3.scene.Spatial)5 BoundingBox (com.jme3.bounding.BoundingBox)4 Material (com.jme3.material.Material)4 BoundingVolume (com.jme3.bounding.BoundingVolume)3 Camera (com.jme3.renderer.Camera)3 TempVars (com.jme3.util.TempVars)3 Matrix4f (com.jme3.math.Matrix4f)2 GeometryList (com.jme3.renderer.queue.GeometryList)2 Vector3f (com.jme3.math.Vector3f)1 Node (com.jme3.scene.Node)1 HashSet (java.util.HashSet)1