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

experimental
Bebul 10 years ago
parent b1f040d8e0
commit 4569154d9f
  1. 24
      jme3-core/src/main/java/com/jme3/renderer/RenderManager.java
  2. 51
      jme3-core/src/main/java/com/jme3/renderer/queue/RenderQueue.java
  3. 13
      jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java
  4. 6
      jme3-core/src/main/java/com/jme3/shadow/BasicShadowRenderer.java
  5. 5
      jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java
  6. 4
      jme3-core/src/main/java/com/jme3/shadow/PointLightShadowRenderer.java
  7. 4
      jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java
  8. 64
      jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java
  9. 3
      jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.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. * Preloads a scene for rendering.
* <p> * <p>

@ -50,8 +50,7 @@ public class RenderQueue {
private GeometryList transparentList; private GeometryList transparentList;
private GeometryList translucentList; private GeometryList translucentList;
private GeometryList skyList; private GeometryList skyList;
@Deprecated private GeometryList shadowRecv; private GeometryList shadowRecv;
@Deprecated private GeometryList shadowCast;
private Spatial rootScene = null; private Spatial rootScene = null;
/** /**
@ -65,7 +64,6 @@ public class RenderQueue {
this.translucentList = new GeometryList(new TransparentComparator()); this.translucentList = new GeometryList(new TransparentComparator());
this.skyList = new GeometryList(new NullComparator()); this.skyList = new GeometryList(new NullComparator());
this.shadowRecv = new GeometryList(new OpaqueComparator()); 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. * Adds a geometry to the given bucket.
* The {@link RenderManager} automatically handles this task * The {@link RenderManager} automatically handles this task
@ -292,14 +263,11 @@ public class RenderQueue {
/** /**
* *
* @param shadBucket The shadow mode to retrieve the {@link GeometryList * @param shadBucket The shadow mode to retrieve the {@link GeometryList
* queue content} for. Only {@link ShadowMode#Cast Cast} and * queue content} for. Only {@link ShadowMode#Receive Receive} is valid.
* {@link ShadowMode#Receive Receive} are valid.
* @return The cast or receive {@link GeometryList} * @return The cast or receive {@link GeometryList}
*/ */
public GeometryList getShadowQueueContent(ShadowMode shadBucket) { public GeometryList getShadowQueueContent(ShadowMode shadBucket) {
switch (shadBucket) { switch (shadBucket) {
case Cast:
return shadowCast;
case Receive: case Receive:
return shadowRecv; return shadowRecv;
default: default:
@ -325,20 +293,6 @@ public class RenderQueue {
renderGeometryList(list, rm, cam, clear); 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) { public boolean isQueueEmpty(Bucket bucket) {
switch (bucket) { switch (bucket) {
case Gui: case Gui:
@ -397,7 +351,6 @@ public class RenderQueue {
transparentList.clear(); transparentList.clear();
translucentList.clear(); translucentList.clear();
skyList.clear(); skyList.clear();
shadowCast.clear();
shadowRecv.clear(); shadowRecv.clear();
} }
} }

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

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

@ -42,7 +42,6 @@ import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.GeometryList; import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.RenderQueue; import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Node; import com.jme3.scene.Node;
@ -175,7 +174,7 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer {
} }
@Override @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 // update frustum points based on current camera and split
ShadowUtil.updateFrustumPoints(viewPort.getCamera(), splitsArray[shadowMapIndex], splitsArray[shadowMapIndex + 1], 1.0f, points); 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) { if (sceneReceivers.size()==0) {
ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), viewPort.getCamera(), RenderQueue.ShadowMode.Receive, sceneReceivers); 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; return shadowMapOccluders;
} }

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

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

@ -39,7 +39,6 @@ import com.jme3.math.Transform;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.GeometryList; import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.RenderQueue; import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
@ -331,23 +330,6 @@ public class ShadowUtil {
shadowCam.setProjectionMatrix(result); 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. * 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. * 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 * all of them one by one against camera frustum the whole Node is checked first
* to hopefully avoid the check on its children. * 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 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; Matrix4f viewProjMatrix;
public Integer casterCount; public Integer casterCount;
BoundingBox splitBB, casterBB; BoundingBox splitBB, casterBB;
@ -380,15 +361,14 @@ public class ShadowUtil {
/** /**
* Check the rootScene against camera frustum and if intersects process it recursively. * Check the rootScene against camera frustum and if intersects process it recursively.
* The global OccludersExtractor variables need to be initialized first. * 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. * Variables are updated and used in {@link ShadowUtil#updateShadowCamera} at last.
*/ */
public int addOccluders() { public int addOccluders(Spatial scene) {
if ( rootScene != null ) addOccluders(rootScene); if ( scene != null ) process(scene);
return casterCount; return casterCount;
} }
private void addOccluders(Spatial scene) { private void process(Spatial scene) {
if (scene.getCullHint() == Spatial.CullHint.Always) return; if (scene.getCullHint() == Spatial.CullHint.Always) return;
RenderQueue.ShadowMode shadowMode = scene.getShadowMode(); RenderQueue.ShadowMode shadowMode = scene.getShadowMode();
@ -460,7 +440,7 @@ public class ShadowUtil {
if ( intersects ) { if ( intersects ) {
for (Spatial child : ((Node)scene).getChildren()) { 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 * Updates the shadow camera to properly contain the given points (which
* contain the eye camera frustum corners) and the shadow occluder objects. * contain the eye camera frustum corners) and the shadow occluder objects
* * collected through the traverse of the scene hierarchy
* @param occluders
* @param shadowCam
* @param points
*/ */
public static void updateShadowCamera(GeometryList occluders, public static void updateShadowCamera(Spatial rootScene,
GeometryList receivers, GeometryList receivers,
Camera shadowCam, Camera shadowCam,
Vector3f[] points, Vector3f[] points,
@ -519,7 +496,7 @@ public class ShadowUtil {
// collect splitOccluders through scene recursive traverse // collect splitOccluders through scene recursive traverse
OccludersExtractor occExt = new OccludersExtractor(viewProjMatrix, casterCount, splitBB, casterBB, splitOccluders, vars); 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 //Nehon 08/18/2010 this is to avoid shadow bleeding when the ground is set to only receive shadows
if (casterCount != receiverCount) { if (casterCount != receiverCount) {
@ -608,24 +585,6 @@ public class ShadowUtil {
vars.release(); vars.release();
shadowCam.setProjectionMatrix(result); 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 * Populates the outputGeometryList with the rootScene children geometries
* of OccludersExtractor.rootScene node that are in the frustum of the given camera * 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 camera the camera to check geometries against
* @param outputGeometryList the list of all geometries that are in the * @param outputGeometryList the list of all geometries that are in the
* camera frustum * camera frustum

@ -42,7 +42,6 @@ import com.jme3.math.FastMath;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.GeometryList; import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.RenderQueue; import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Node; import com.jme3.scene.Node;
@ -143,7 +142,7 @@ public class SpotLightShadowRenderer extends AbstractShadowRenderer {
} }
@Override @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); ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), shadowCam, RenderQueue.ShadowMode.Cast, shadowMapOccluders);
return shadowMapOccluders; return shadowMapOccluders;
} }

Loading…
Cancel
Save