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. "
This commit is contained in:
@@ -353,7 +353,7 @@ public:
|
||||
|
||||
void update(const osg::Vec3& v)
|
||||
{
|
||||
if (v.z()<0.0f)
|
||||
if (v.z()<-1.0f)
|
||||
{
|
||||
//OSG_NOTICE<<"discarding("<<v<<")"<<std::endl;
|
||||
return;
|
||||
@@ -1464,7 +1464,7 @@ bool ViewDependentShadowMap::computeShadowCameraSettings(Frustum& frustum, Light
|
||||
else
|
||||
{
|
||||
projectionMatrix.makeOrtho(xMin,xMax, yMin, yMax,0.0,zMax-zMin);
|
||||
viewMatrix.makeLookAt(frustum.center+positionedLight.lightDir*zMin, frustum.center, lightUp);
|
||||
viewMatrix.makeLookAt(frustum.center+positionedLight.lightDir*zMin, frustum.center+positionedLight.lightDir*zMax, lightUp);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user