PSSM : fixed wrong shadows when frustum near clip is 0 or negative (parallel projection issue)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8246 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 0775b93088
commit 6ed981db10
  1. 21
      engine/src/desktop-fx/com/jme3/shadow/PssmShadowRenderer.java

@ -330,23 +330,18 @@ public class PssmShadowRenderer implements SceneProcessor {
float zFar = zFarOverride; float zFar = zFarOverride;
if (zFar == 0) { if (zFar == 0) {
zFar = viewCam.getFrustumFar(); zFar = viewCam.getFrustumFar();
// zFar = PssmShadowUtil.computeZFar(occluders, receivers, viewCam);
} }
// System.out.println("Zfar : "+zFar);
ShadowUtil.updateFrustumPoints(viewCam, viewCam.getFrustumNear(), zFar, 1.0f, points);
// Vector3f frustaCenter = new Vector3f(); //We prevent computing the frustum points and splits with zeroed or negative near clip value
// for (Vector3f point : points) { float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
// frustaCenter.addLocal(point); ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
// }
// frustaCenter.multLocal(1f / 8f);
//shadowCam.setDirection(direction); //shadowCam.setDirection(direction);
shadowCam.getRotation().lookAt(direction, shadowCam.getUp()); shadowCam.getRotation().lookAt(direction, shadowCam.getUp());
shadowCam.update(); shadowCam.update();
shadowCam.updateViewProjection(); shadowCam.updateViewProjection();
PssmShadowUtil.updateFrustumSplits(splitsArray, viewCam.getFrustumNear(), zFar, lambda); PssmShadowUtil.updateFrustumSplits(splitsArray, frustumNear, zFar, lambda);
switch (splitsArray.length) { switch (splitsArray.length) {
@ -394,7 +389,7 @@ public class PssmShadowRenderer implements SceneProcessor {
renderManager.setCamera(viewCam, false); renderManager.setCamera(viewCam, false);
} }
//debug only : displays depth shadow maps //debug only : displays depth shadow maps
private void displayShadowMap(Renderer r) { private void displayShadowMap(Renderer r) {
Camera cam = viewPort.getCamera(); Camera cam = viewPort.getCamera();
@ -425,9 +420,9 @@ public class PssmShadowRenderer implements SceneProcessor {
postshadowMat.setMatrix4("LightViewProjectionMatrix" + i, lightViewProjectionsMatrices[i]); postshadowMat.setMatrix4("LightViewProjectionMatrix" + i, lightViewProjectionsMatrices[i]);
} }
renderManager.setForcedMaterial(postshadowMat); renderManager.setForcedMaterial(postshadowMat);
viewPort.getQueue().renderShadowQueue(ShadowMode.Receive, renderManager, cam, flushQueues); viewPort.getQueue().renderShadowQueue(ShadowMode.Receive, renderManager, cam, flushQueues);
renderManager.setForcedMaterial(null); renderManager.setForcedMaterial(null);
renderManager.setCamera(cam, false); renderManager.setCamera(cam, false);
@ -524,7 +519,7 @@ public class PssmShadowRenderer implements SceneProcessor {
this.edgesThickness *= 0.1f; this.edgesThickness *= 0.1f;
postshadowMat.setFloat("PCFEdge", edgesThickness); postshadowMat.setFloat("PCFEdge", edgesThickness);
} }
/** /**
* returns true if the PssmRenderer flushed the shadow queues * returns true if the PssmRenderer flushed the shadow queues
* @return flushQueues * @return flushQueues

Loading…
Cancel
Save