fix renderShadow optimization to work on multiple scenes attached to viewPort properly

experimental
Bebul 10 years ago
parent 4569154d9f
commit ed369135fa
  1. 2
      jme3-core/src/main/java/com/jme3/renderer/RenderManager.java
  2. 9
      jme3-core/src/main/java/com/jme3/renderer/queue/RenderQueue.java
  3. 6
      jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java
  4. 7
      jme3-core/src/main/java/com/jme3/shadow/BasicShadowRenderer.java
  5. 11
      jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java
  6. 9
      jme3-core/src/main/java/com/jme3/shadow/PointLightShadowRenderer.java
  7. 6
      jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java
  8. 8
      jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java
  9. 9
      jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.java

@ -658,8 +658,6 @@ public class RenderManager {
public void renderScene(Spatial scene, ViewPort vp) { public void renderScene(Spatial scene, ViewPort vp) {
//reset of the camera plane state for proper culling (must be 0 for the first note of the scene to be rendered) //reset of the camera plane state for proper culling (must be 0 for the first note of the scene to be rendered)
vp.getCamera().setPlaneState(0); vp.getCamera().setPlaneState(0);
//remember the scene for possible later use
vp.getQueue().setRootScene(scene);
//rendering the scene //rendering the scene
renderSubScene(scene, vp); renderSubScene(scene, vp);
} }

@ -51,7 +51,6 @@ public class RenderQueue {
private GeometryList translucentList; private GeometryList translucentList;
private GeometryList skyList; private GeometryList skyList;
private GeometryList shadowRecv; private GeometryList shadowRecv;
private Spatial rootScene = null;
/** /**
* Creates a new RenderQueue, the default {@link GeometryComparator comparators} * Creates a new RenderQueue, the default {@link GeometryComparator comparators}
@ -337,14 +336,6 @@ public class RenderQueue {
} }
} }
public void setRootScene(Spatial rs) {
rootScene = rs;
}
public Spatial getRootScene() {
return rootScene;
}
public void clear() { public void clear() {
opaqueList.clear(); opaqueList.clear();
guiList.clear(); guiList.clear();

@ -489,9 +489,6 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable
//rendering the post shadow pass //rendering the post shadow pass
viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false); viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
if (flushQueues) {
sceneReceivers.clear();
}
//resetting renderManager settings //resetting renderManager settings
renderManager.setForcedTechnique(null); renderManager.setForcedTechnique(null);
@ -502,6 +499,9 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable
clearMatParams(); clearMatParams();
} }
if (flushQueues) {
sceneReceivers.clear();
}
} }
/** /**

@ -43,6 +43,7 @@ import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.OpaqueComparator; import com.jme3.renderer.queue.OpaqueComparator;
import com.jme3.renderer.queue.RenderQueue; import com.jme3.renderer.queue.RenderQueue;
import com.jme3.renderer.queue.RenderQueue.ShadowMode; import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Spatial;
import com.jme3.texture.FrameBuffer; import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture2D; import com.jme3.texture.Texture2D;
@ -146,7 +147,9 @@ public class BasicShadowRenderer implements SceneProcessor {
} }
public void postQueue(RenderQueue rq) { public void postQueue(RenderQueue rq) {
ShadowUtil.getGeometriesInCamFrustum(rq.getRootScene(), viewPort.getCamera(), ShadowMode.Receive, lightReceivers); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), ShadowMode.Receive, lightReceivers);
}
// update frustum points based on current camera // update frustum points based on current camera
Camera viewCam = viewPort.getCamera(); Camera viewCam = viewPort.getCamera();
@ -174,7 +177,7 @@ public class BasicShadowRenderer implements SceneProcessor {
shadowCam.updateViewProjection(); shadowCam.updateViewProjection();
// render shadow casters to shadow map // render shadow casters to shadow map
ShadowUtil.updateShadowCamera(rq.getRootScene(), lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize); ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize);
if (shadowOccluders.size() == 0) { if (shadowOccluders.size() == 0) {
noOccluders = true; noOccluders = true;
return; return;

@ -45,6 +45,7 @@ import com.jme3.renderer.Camera;
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;
import com.jme3.scene.Spatial;
import java.io.IOException; import java.io.IOException;
/** /**
@ -181,9 +182,11 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer {
//Updating shadow cam with curent split frustra //Updating shadow cam with curent split frustra
if (sceneReceivers.size()==0) { if (sceneReceivers.size()==0) {
ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), viewPort.getCamera(), RenderQueue.ShadowMode.Receive, sceneReceivers); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), RenderQueue.ShadowMode.Receive, sceneReceivers);
}
} }
ShadowUtil.updateShadowCamera(viewPort.getQueue().getRootScene(), sceneReceivers, shadowCam, points, shadowMapOccluders, stabilize?shadowMapSize:0); ShadowUtil.updateShadowCamera(viewPort, sceneReceivers, shadowCam, points, shadowMapOccluders, stabilize?shadowMapSize:0);
return shadowMapOccluders; return shadowMapOccluders;
} }
@ -191,7 +194,9 @@ public class DirectionalLightShadowRenderer extends AbstractShadowRenderer {
@Override @Override
GeometryList getReceivers(GeometryList sceneReceivers, GeometryList lightReceivers) { GeometryList getReceivers(GeometryList sceneReceivers, GeometryList lightReceivers) {
if (sceneReceivers.size()==0) { if (sceneReceivers.size()==0) {
ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), viewPort.getCamera(), RenderQueue.ShadowMode.Receive, sceneReceivers); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), RenderQueue.ShadowMode.Receive, sceneReceivers);
}
} }
lightReceivers = sceneReceivers; lightReceivers = sceneReceivers;
return sceneReceivers; return sceneReceivers;

@ -44,6 +44,7 @@ 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;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.util.TempVars; import com.jme3.util.TempVars;
import java.io.IOException; import java.io.IOException;
@ -131,14 +132,18 @@ public class PointLightShadowRenderer extends AbstractShadowRenderer {
@Override @Override
protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) { protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) {
ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), shadowCams[shadowMapIndex], RenderQueue.ShadowMode.Cast, shadowMapOccluders); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getGeometriesInCamFrustum(scene, shadowCams[shadowMapIndex], RenderQueue.ShadowMode.Cast, shadowMapOccluders);
}
return shadowMapOccluders; return shadowMapOccluders;
} }
@Override @Override
GeometryList getReceivers(GeometryList sceneReceivers, GeometryList lightReceivers) { GeometryList getReceivers(GeometryList sceneReceivers, GeometryList lightReceivers) {
lightReceivers.clear(); lightReceivers.clear();
ShadowUtil.getLitGeometriesInViewPort(viewPort.getQueue().getRootScene(), viewPort.getCamera(), shadowCams, RenderQueue.ShadowMode.Receive, lightReceivers); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getLitGeometriesInViewPort(scene, viewPort.getCamera(), shadowCams, RenderQueue.ShadowMode.Receive, lightReceivers);
}
return lightReceivers; return lightReceivers;
} }

@ -387,7 +387,9 @@ public class PssmShadowRenderer implements SceneProcessor {
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
public void postQueue(RenderQueue rq) { public void postQueue(RenderQueue rq) {
ShadowUtil.getGeometriesInCamFrustum(rq.getRootScene(), viewPort.getCamera(), ShadowMode.Receive, lightReceivers); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), ShadowMode.Receive, lightReceivers);
}
Camera viewCam = viewPort.getCamera(); Camera viewCam = viewPort.getCamera();
@ -431,7 +433,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.updateShadowCamera(rq.getRootScene(), lightReceivers, shadowCam, points, splitOccluders, shadowMapSize); ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, splitOccluders, shadowMapSize);
//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,6 +39,7 @@ 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.ViewPort;
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;
@ -452,7 +453,7 @@ public class ShadowUtil {
* 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 * collected through the traverse of the scene hierarchy
*/ */
public static void updateShadowCamera(Spatial rootScene, public static void updateShadowCamera(ViewPort viewPort,
GeometryList receivers, GeometryList receivers,
Camera shadowCam, Camera shadowCam,
Vector3f[] points, Vector3f[] points,
@ -496,7 +497,10 @@ 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(rootScene); for (Spatial scene : viewPort.getScenes()) {
occExt.addOccluders(scene);
}
casterCount = occExt.casterCount;
//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) {

@ -45,6 +45,7 @@ import com.jme3.renderer.Camera;
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;
import com.jme3.scene.Spatial;
import com.jme3.util.TempVars; import com.jme3.util.TempVars;
import java.io.IOException; import java.io.IOException;
@ -143,7 +144,9 @@ public class SpotLightShadowRenderer extends AbstractShadowRenderer {
@Override @Override
protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) { protected GeometryList getOccludersToRender(int shadowMapIndex, GeometryList shadowMapOccluders) {
ShadowUtil.getGeometriesInCamFrustum(viewPort.getQueue().getRootScene(), shadowCam, RenderQueue.ShadowMode.Cast, shadowMapOccluders); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getGeometriesInCamFrustum(scene, shadowCam, RenderQueue.ShadowMode.Cast, shadowMapOccluders);
}
return shadowMapOccluders; return shadowMapOccluders;
} }
@ -152,7 +155,9 @@ public class SpotLightShadowRenderer extends AbstractShadowRenderer {
lightReceivers.clear(); lightReceivers.clear();
Camera[] cameras = new Camera[1]; Camera[] cameras = new Camera[1];
cameras[0] = shadowCam; cameras[0] = shadowCam;
ShadowUtil.getLitGeometriesInViewPort(viewPort.getQueue().getRootScene(), viewPort.getCamera(), cameras, RenderQueue.ShadowMode.Receive, lightReceivers); for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getLitGeometriesInViewPort(scene, viewPort.getCamera(), cameras, RenderQueue.ShadowMode.Receive, lightReceivers);
}
return lightReceivers; return lightReceivers;
} }

Loading…
Cancel
Save