Pārlūkot izejas kodu

RenderShadow relict code clean up, no more static ShadowUtils.rootScene

Bebul 10 gadi atpakaļ
vecāks
revīzija
4569154d9f

+ 0 - 24
jme3-core/src/main/java/com/jme3/renderer/RenderManager.java

@@ -586,30 +586,6 @@ public class RenderManager {
         }
     }
 
-    /**
-     * If a spatial is not inside the eye frustum, it
-     * is still rendered in the shadow frustum (shadow casting queue)
-     * through this recursive method.
-     */
-    @Deprecated
-    private void renderShadow(Spatial s, RenderQueue rq) {
-        if (s instanceof Node) {
-            Node n = (Node) s;
-            List<Spatial> children = n.getChildren();
-            for (int i = 0; i < children.size(); i++) {
-                renderShadow(children.get(i), rq);
-            }
-        } else if (s instanceof Geometry) {
-            Geometry gm = (Geometry) s;
-
-            RenderQueue.ShadowMode shadowMode = s.getShadowMode();
-            if (shadowMode != RenderQueue.ShadowMode.Off && shadowMode != RenderQueue.ShadowMode.Receive && !gm.isGrouped()) {
-                //forcing adding to shadow cast mode, culled objects doesn't have to be in the receiver queue
-                rq.addToShadowQueue(gm, RenderQueue.ShadowMode.Cast);
-            }
-        }
-    }
-
     /**
      * Preloads a scene for rendering.
      * <p>

+ 2 - 49
jme3-core/src/main/java/com/jme3/renderer/queue/RenderQueue.java

@@ -50,8 +50,7 @@ public class RenderQueue {
     private GeometryList transparentList;
     private GeometryList translucentList;
     private GeometryList skyList;
-    @Deprecated private GeometryList shadowRecv;
-    @Deprecated private GeometryList shadowCast;
+    private GeometryList shadowRecv;
     private Spatial rootScene = null;
 
     /**
@@ -65,7 +64,6 @@ public class RenderQueue {
         this.translucentList = new GeometryList(new TransparentComparator());
         this.skyList = new GeometryList(new NullComparator());
         this.shadowRecv = new GeometryList(new OpaqueComparator());
-        this.shadowCast = new GeometryList(new OpaqueComparator());
     }
 
     /**
@@ -230,33 +228,6 @@ public class RenderQueue {
         }
     }
 
-    /**
-     * Adds a geometry to a shadow bucket.
-     * Note that this operation is done automatically by the
-     * {@link RenderManager}. {@link SceneProcessor}s that handle
-     * shadow rendering should fetch the queue by using
-     * {@link #getShadowQueueContent(com.jme3.renderer.queue.RenderQueue.ShadowMode) },
-     * by default no action is taken on the shadow queues.
-     * 
-     * @param g The geometry to add
-     * @param shadBucket The shadow bucket type, if it is
-     * {@link ShadowMode#CastAndReceive}, it is added to both the cast
-     * and the receive buckets.
-     */
-    @Deprecated
-    public void addToShadowQueue(Geometry g, ShadowMode shadBucket) {
-        switch (shadBucket) {
-            case Inherit:
-            case Off:
-            case Cast:
-            case Receive:
-            case CastAndReceive:
-                break;
-            default:
-                throw new UnsupportedOperationException("Unrecognized shadow bucket type: " + shadBucket);
-        }
-    }
-
     /**
      * Adds a geometry to the given bucket.
      * The {@link RenderManager} automatically handles this task
@@ -292,14 +263,11 @@ public class RenderQueue {
     /**
      * 
      * @param shadBucket The shadow mode to retrieve the {@link GeometryList
-     * queue content} for.  Only {@link ShadowMode#Cast Cast} and
-     * {@link ShadowMode#Receive Receive} are valid.
+     * queue content} for.  Only {@link ShadowMode#Receive Receive} is valid.
      * @return The cast or receive {@link GeometryList}
      */
     public GeometryList getShadowQueueContent(ShadowMode shadBucket) {
         switch (shadBucket) {
-            case Cast:
-                return shadowCast;
             case Receive:
                 return shadowRecv;
             default:
@@ -325,20 +293,6 @@ public class RenderQueue {
         renderGeometryList(list, rm, cam, clear);
     }
 
-    @Deprecated
-    public void renderShadowQueue(ShadowMode shadBucket, RenderManager rm, Camera cam, boolean clear) {
-        switch (shadBucket) {
-            case Cast:
-                renderGeometryList(shadowCast, rm, cam, clear);
-                break;
-            case Receive:
-                renderGeometryList(shadowRecv, rm, cam, clear);
-                break;
-            default:
-                throw new IllegalArgumentException("Unexpected shadow bucket: " + shadBucket);
-        }
-    }
-
     public boolean isQueueEmpty(Bucket bucket) {
         switch (bucket) {
             case Gui:
@@ -397,7 +351,6 @@ public class RenderQueue {
         transparentList.clear();
         translucentList.clear();
         skyList.clear();
-        shadowCast.clear();
         shadowRecv.clear();
     }
 }

+ 5 - 8
jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java

@@ -363,7 +363,7 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable
      * @param shadowMapOcculders
      * @return
      */
-    protected abstract GeometryList getOccludersToRender(int shadowMapIndex, GeometryList sceneOccluders, GeometryList sceneReceivers, GeometryList shadowMapOccluders);
+    protected abstract GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders);
 
     /**
      * return the shadow camera to use for rendering the shadow map according
@@ -385,7 +385,6 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable
 
     @SuppressWarnings("fallthrough")
     public void postQueue(RenderQueue rq) {
-        GeometryList occluders = rq.getShadowQueueContent(ShadowMode.Cast);
         sceneReceivers = rq.getShadowQueueContent(ShadowMode.Receive);
         lightReceivers.clear();
         skipPostPass = false;
@@ -405,14 +404,12 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable
                 if (debugfrustums) {
                     doDisplayFrustumDebug(shadowMapIndex);
                 }
-                renderShadowMap(shadowMapIndex, occluders, sceneReceivers);
+                renderShadowMap(shadowMapIndex);
 
             }
 
         debugfrustums = false;
-        if (flushQueues) {
-            occluders.clear();
-        }
+
         //restore setting for future rendering
         r.setFrameBuffer(viewPort.getOutputFrameBuffer());
         renderManager.setForcedMaterial(null);
@@ -421,8 +418,8 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable
         
     }
 
-    protected void renderShadowMap(int shadowMapIndex, GeometryList occluders, GeometryList receivers) {
-        shadowMapOccluders = getOccludersToRender(shadowMapIndex, occluders, receivers, shadowMapOccluders);
+    protected void renderShadowMap(int shadowMapIndex) {
+        shadowMapOccluders = getOccludersToRender(shadowMapIndex, shadowMapOccluders);
         Camera shadowCam = getShadowCam(shadowMapIndex);
 
         //saving light view projection matrix for this split            

+ 2 - 4
jme3-core/src/main/java/com/jme3/shadow/BasicShadowRenderer.java

@@ -174,9 +174,7 @@ public class BasicShadowRenderer implements SceneProcessor {
         shadowCam.updateViewProjection();
 
         // render shadow casters to shadow map
-        ShadowUtil.rootScene = rq.getRootScene();
-        ShadowUtil.updateShadowCamera(null, lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize);
-        ShadowUtil.rootScene = null;
+        ShadowUtil.updateShadowCamera(rq.getRootScene(), lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize);
         if (shadowOccluders.size() == 0) {
             noOccluders = true;
             return;
@@ -209,7 +207,7 @@ public class BasicShadowRenderer implements SceneProcessor {
         if (!noOccluders) {
             postshadowMat.setMatrix4("LightViewProjectionMatrix", shadowCam.getViewProjectionMatrix());
             renderManager.setForcedMaterial(postshadowMat);
-            viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, shadowCam, true);
+            viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, viewPort.getCamera(), true);
             renderManager.setForcedMaterial(null);
         }
     }

+ 2 - 3
jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java

@@ -42,7 +42,6 @@ import com.jme3.math.ColorRGBA;
 import com.jme3.math.Vector2f;
 import com.jme3.math.Vector3f;
 import com.jme3.renderer.Camera;
-import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.queue.GeometryList;
 import com.jme3.renderer.queue.RenderQueue;
 import com.jme3.scene.Node;
@@ -175,7 +174,7 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer {
     }
     
     @Override
-    protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList sceneOccluders, GeometryList sceneReceivers, GeometryList shadowMapOccluders) {
+    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);
@@ -184,7 +183,7 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer {
         if (sceneReceivers.size()==0) {
             ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), viewPort.getCamera(), RenderQueue.ShadowMode.Receive, sceneReceivers);
         }
-        ShadowUtil.updateShadowCameraFromRoot(viewPort.getQueue().getRootScene(), sceneReceivers, shadowCam, points, shadowMapOccluders, stabilize?shadowMapSize:0);
+        ShadowUtil.updateShadowCamera(viewPort.getQueue().getRootScene(), sceneReceivers, shadowCam, points, shadowMapOccluders, stabilize?shadowMapSize:0);
 
         return shadowMapOccluders;
     }

+ 1 - 3
jme3-core/src/main/java/com/jme3/shadow/PointLightShadowRenderer.java

@@ -40,9 +40,7 @@ import com.jme3.light.PointLight;
 import com.jme3.material.Material;
 import com.jme3.math.Vector3f;
 import com.jme3.renderer.Camera;
-import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.queue.GeometryList;
-import com.jme3.renderer.queue.OpaqueComparator;
 import com.jme3.renderer.queue.RenderQueue;
 import com.jme3.scene.Geometry;
 import com.jme3.scene.Node;
@@ -132,7 +130,7 @@ public class PointLightShadowRenderer extends AbstractShadowRenderer {
     }
 
     @Override
-    protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList sceneOccluders, GeometryList sceneReceivers, GeometryList shadowMapOccluders) {
+    protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) {
         ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), shadowCams[shadowMapIndex], RenderQueue.ShadowMode.Cast, shadowMapOccluders);
         return shadowMapOccluders;
     }

+ 1 - 3
jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java

@@ -431,9 +431,7 @@ public class PssmShadowRenderer implements SceneProcessor {
             ShadowUtil.updateFrustumPoints(viewCam, splitsArray[i], splitsArray[i + 1], 1.0f, points);
 
             //Updating shadow cam with curent split frustra
-            ShadowUtil.rootScene = rq.getRootScene();
-            ShadowUtil.updateShadowCamera(null, lightReceivers, shadowCam, points, splitOccluders, shadowMapSize);
-            ShadowUtil.rootScene = null;
+            ShadowUtil.updateShadowCamera(rq.getRootScene(), lightReceivers, shadowCam, points, splitOccluders, shadowMapSize);
 
             //saving light view projection matrix for this split            
             lightViewProjectionsMatrices[i].set(shadowCam.getViewProjectionMatrix());

+ 13 - 53
jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java

@@ -39,7 +39,6 @@ import com.jme3.math.Transform;
 import com.jme3.math.Vector2f;
 import com.jme3.math.Vector3f;
 import com.jme3.renderer.Camera;
-import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.queue.GeometryList;
 import com.jme3.renderer.queue.RenderQueue;
 import com.jme3.scene.Geometry;
@@ -331,23 +330,6 @@ public class ShadowUtil {
         shadowCam.setProjectionMatrix(result);
     }
 
-    /**
-     * Updates the shadow camera to properly contain the given points (which
-     * contain the eye camera frustum corners) and the shadow occluder objects.
-     *
-     * @param occluders
-     * @param receivers
-     * @param shadowCam
-     * @param points
-     */
-    public static void updateShadowCamera(GeometryList occluders,
-            GeometryList receivers,
-            Camera shadowCam,
-            Vector3f[] points,
-            float shadowMapSize) {
-        updateShadowCamera(occluders, receivers, shadowCam, points, null, shadowMapSize);
-    }
-    
     /**
      * OccludersExtractor is a helper class to collect splitOccluders from scene recursively.
      * It utilizes the scene hierarchy, instead of making the huge flat geometries list first.
@@ -355,10 +337,9 @@ public class ShadowUtil {
      * all of them one by one against camera frustum the whole Node is checked first
      * to hopefully avoid the check on its children.
      */
-    static public Spatial rootScene = null; // static global used for OccludersExtractor in order not to change public ShadoUtil.updateShadowCamera interface
     public static class OccludersExtractor
     {
-        // global variables set in order not to have recursive addOccluders method with too many parameters
+        // global variables set in order not to have recursive process method with too many parameters
         Matrix4f viewProjMatrix;
         public Integer casterCount;
         BoundingBox splitBB, casterBB;
@@ -380,15 +361,14 @@ public class ShadowUtil {
         /**
          * Check the rootScene against camera frustum and if intersects process it recursively.
          * The global OccludersExtractor variables need to be initialized first.
-         * The {@link OccludersExtractor#rootScene} need to be set before the call to {@link ShadowUtil#updateShadowCamera}
          * Variables are updated and used in {@link ShadowUtil#updateShadowCamera} at last.
          */
-        public int addOccluders() {
-            if ( rootScene != null ) addOccluders(rootScene);
+        public int addOccluders(Spatial scene) {
+            if ( scene != null ) process(scene);
             return casterCount;
         }
         
-        private void addOccluders(Spatial scene) {
+        private void process(Spatial scene) {
             if (scene.getCullHint() == Spatial.CullHint.Always) return;
 
             RenderQueue.ShadowMode shadowMode = scene.getShadowMode();
@@ -460,7 +440,7 @@ public class ShadowUtil {
  
                 if ( intersects ) {
                     for (Spatial child : ((Node)scene).getChildren()) {
-                        addOccluders(child);
+                        process(child);
                     }
                 }
             }
@@ -469,13 +449,10 @@ public class ShadowUtil {
     
     /**
      * Updates the shadow camera to properly contain the given points (which
-     * contain the eye camera frustum corners) and the shadow occluder objects.
-     *
-     * @param occluders
-     * @param shadowCam
-     * @param points
+     * contain the eye camera frustum corners) and the shadow occluder objects
+     * collected through the traverse of the scene hierarchy
      */
-    public static void updateShadowCamera(GeometryList occluders,
+    public static void updateShadowCamera(Spatial rootScene,
             GeometryList receivers,
             Camera shadowCam,
             Vector3f[] points,
@@ -519,8 +496,8 @@ public class ShadowUtil {
 
         // collect splitOccluders through scene recursive traverse
         OccludersExtractor occExt = new OccludersExtractor(viewProjMatrix, casterCount, splitBB, casterBB, splitOccluders, vars);
-        casterCount = occExt.addOccluders(); // the rootScene inside
-
+        casterCount = occExt.addOccluders(rootScene);
+  
         //Nehon 08/18/2010 this is to avoid shadow bleeding when the ground is set to only receive shadows
         if (casterCount != receiverCount) {
             casterBB.setXExtent(casterBB.getXExtent() + 2.0f);
@@ -608,24 +585,6 @@ public class ShadowUtil {
         vars.release();
 
         shadowCam.setProjectionMatrix(result);
-
-    }
-
-    /**
-     * Updates the shadow camera to properly contain the given points (which
-     * contain the eye camera frustum corners) and the shadow occluder objects.
-     *
-     * Render Shadow optimization to traverse the scene hierarchy instead of using the whole, but flattened, scene
-     */
-    public static void updateShadowCameraFromRoot(Spatial rootScene,
-            GeometryList receivers,
-            Camera shadowCam,
-            Vector3f[] points,
-            GeometryList splitOccluders,
-            float shadowMapSize) {
-        ShadowUtil.rootScene = rootScene;
-        ShadowUtil.updateShadowCamera(null, receivers, shadowCam, points, splitOccluders, shadowMapSize);
-        ShadowUtil.rootScene = null;
     }
     
     /**
@@ -654,9 +613,10 @@ public class ShadowUtil {
     }
 
     /**
-     * Populates the outputGeometryList with the geometries of the children 
-     * of OccludersExtractor.rootScene node that are in the frustum of the given camera
+     * Populates the outputGeometryList with the rootScene children geometries
+     * that are in the frustum of the given camera
      *
+     * @param rootScene the rootNode of the scene to traverse
      * @param camera the camera to check geometries against
      * @param outputGeometryList the list of all geometries that are in the
      * camera frustum

+ 1 - 2
jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.java

@@ -42,7 +42,6 @@ import com.jme3.math.FastMath;
 import com.jme3.math.Vector2f;
 import com.jme3.math.Vector3f;
 import com.jme3.renderer.Camera;
-import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.queue.GeometryList;
 import com.jme3.renderer.queue.RenderQueue;
 import com.jme3.scene.Node;
@@ -143,7 +142,7 @@ public class SpotLightShadowRenderer extends AbstractShadowRenderer {
     }
 
     @Override
-    protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList sceneOccluders, GeometryList sceneReceivers, GeometryList shadowMapOccluders) {
+    protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) {
         ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), shadowCam, RenderQueue.ShadowMode.Cast, shadowMapOccluders);
         return shadowMapOccluders;
     }