From e5b5494fe158215486ff20f99d8b86704f7cb8bc Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 14 Mar 2012 16:42:07 +0000 Subject: [PATCH] From Wang Rui, "I'd like to submit a slightly modified version of the ViewDependentShadowMap. It includes two fixes: one is in ComputeLightSpaceBounds::update(), which changes the statement "if (v.z()<0.0f)" to "if (v.z()<-1.0f)" as clipping space coordinates should be transformed to [-1, 1] and should not be discarded unless they go beyond the range; the other is in ViewDependentShadowMap::computeShadowCameraSettings(), in which I changed the line: viewMatrix.makeLookAt(frustum.center+positionedLight.lightDir*zMin, frustum.center, lightUp); to viewMatrix.makeLookAt(frustum.center+positionedLight.lightDir*zMin, frustum.center+positionedLight.lightDir*zMax, lightUp); The reason I've done such a change is that for huge scenes like a city on the earth, the values of frustum.center can be extremely large, but zMin may be very small (e.g., when model depth in light coords equals the model radius by chance) in some cases so the result of (eye - center) might jiggle while moving around the shadow scene and thus make the shadow map suddenly disappear some time. The small change here also considers the effect of zMax to avoid such problems. " --- src/osgShadow/ViewDependentShadowMap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index d4eb684b7..93df2c68c 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -353,7 +353,7 @@ public: void update(const osg::Vec3& v) { - if (v.z()<0.0f) + if (v.z()<-1.0f) { //OSG_NOTICE<<"discarding("<