To fix problems in tight bound computation of the shadow map made the ComputeLightSpaceBounds usage always used when the
CastShadowMask is active. Changed the ComputeLightSpaceBounds to use just VIEW_FRUSTUM_CULLING.
This commit is contained in:
parent
2b2c1b5671
commit
16c2bb5a2f
@ -254,6 +254,8 @@ public:
|
|||||||
ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix):
|
ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix):
|
||||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN)
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN)
|
||||||
{
|
{
|
||||||
|
setCullingMode(osg::CullSettings::VIEW_FRUSTUM_CULLING);
|
||||||
|
|
||||||
pushViewport(viewport);
|
pushViewport(viewport);
|
||||||
pushProjectionMatrix(new osg::RefMatrix(projectionMatrix));
|
pushProjectionMatrix(new osg::RefMatrix(projectionMatrix));
|
||||||
pushModelViewMatrix(new osg::RefMatrix(viewMatrix),osg::Transform::ABSOLUTE_RF);
|
pushModelViewMatrix(new osg::RefMatrix(viewMatrix),osg::Transform::ABSOLUTE_RF);
|
||||||
@ -263,13 +265,22 @@ public:
|
|||||||
{
|
{
|
||||||
if (isCulled(node)) return;
|
if (isCulled(node)) return;
|
||||||
|
|
||||||
|
// push the culling mode.
|
||||||
|
pushCurrentMask();
|
||||||
|
|
||||||
traverse(node);
|
traverse(node);
|
||||||
|
|
||||||
|
// pop the culling mode.
|
||||||
|
popCurrentMask();
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply(osg::Geode& node)
|
void apply(osg::Geode& node)
|
||||||
{
|
{
|
||||||
if (isCulled(node)) return;
|
if (isCulled(node)) return;
|
||||||
|
|
||||||
|
// push the culling mode.
|
||||||
|
pushCurrentMask();
|
||||||
|
|
||||||
for(unsigned int i=0; i<node.getNumDrawables();++i)
|
for(unsigned int i=0; i<node.getNumDrawables();++i)
|
||||||
{
|
{
|
||||||
if (node.getDrawable(i))
|
if (node.getDrawable(i))
|
||||||
@ -277,6 +288,9 @@ public:
|
|||||||
updateBound(node.getDrawable(i)->getBound());
|
updateBound(node.getDrawable(i)->getBound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pop the culling mode.
|
||||||
|
popCurrentMask();
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply(osg::Billboard&)
|
void apply(osg::Billboard&)
|
||||||
@ -295,9 +309,12 @@ public:
|
|||||||
{
|
{
|
||||||
if (isCulled(transform)) return;
|
if (isCulled(transform)) return;
|
||||||
|
|
||||||
// absolute transforms won't affect a shadow map so their subgraphs should be ignored.
|
// push the culling mode.
|
||||||
if (transform.getReferenceFrame()==osg::Transform::ABSOLUTE_RF) return;
|
pushCurrentMask();
|
||||||
|
|
||||||
|
// absolute transforms won't affect a shadow map so their subgraphs should be ignored.
|
||||||
|
if (transform.getReferenceFrame()==osg::Transform::RELATIVE_RF)
|
||||||
|
{
|
||||||
osg::ref_ptr<osg::RefMatrix> matrix = new osg::RefMatrix(*getModelViewMatrix());
|
osg::ref_ptr<osg::RefMatrix> matrix = new osg::RefMatrix(*getModelViewMatrix());
|
||||||
transform.computeLocalToWorldMatrix(*matrix,this);
|
transform.computeLocalToWorldMatrix(*matrix,this);
|
||||||
pushModelViewMatrix(matrix.get(), transform.getReferenceFrame());
|
pushModelViewMatrix(matrix.get(), transform.getReferenceFrame());
|
||||||
@ -307,6 +324,11 @@ public:
|
|||||||
popModelViewMatrix();
|
popModelViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pop the culling mode.
|
||||||
|
popCurrentMask();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void apply(osg::Camera&)
|
void apply(osg::Camera&)
|
||||||
{
|
{
|
||||||
// camera nodes won't affect a shadow map so their subgraphs should be ignored
|
// camera nodes won't affect a shadow map so their subgraphs should be ignored
|
||||||
@ -336,14 +358,12 @@ public:
|
|||||||
//OSG_NOTICE<<"discarding("<<v<<")"<<std::endl;
|
//OSG_NOTICE<<"discarding("<<v<<")"<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float x = v.x();
|
float x = v.x();
|
||||||
if (x<-1.0f) x=-1.0f;
|
if (x<-1.0f) x=-1.0f;
|
||||||
if (x>1.0f) x=1.0f;
|
if (x>1.0f) x=1.0f;
|
||||||
float y = v.y();
|
float y = v.y();
|
||||||
if (y<-1.0f) y=-1.0f;
|
if (y<-1.0f) y=-1.0f;
|
||||||
if (y>1.0f) y=1.0f;
|
if (y>1.0f) y=1.0f;
|
||||||
|
|
||||||
_bb.expandBy(osg::Vec3(x,y,v.z()));
|
_bb.expandBy(osg::Vec3(x,y,v.z()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,7 +857,7 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
|
|||||||
|
|
||||||
// if we are using multiple shadow maps and CastShadowTraversalMask is being used
|
// if we are using multiple shadow maps and CastShadowTraversalMask is being used
|
||||||
// traverse the scene to compute the extents of the objects
|
// traverse the scene to compute the extents of the objects
|
||||||
if (numShadowMapsPerLight>1 && _shadowedScene->getCastsShadowTraversalMask()!=0xffffffff)
|
if (/*numShadowMapsPerLight>1 &&*/ _shadowedScene->getCastsShadowTraversalMask()!=0xffffffff)
|
||||||
{
|
{
|
||||||
// osg::ElapsedTime timer;
|
// osg::ElapsedTime timer;
|
||||||
|
|
||||||
@ -852,7 +872,6 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
|
|||||||
|
|
||||||
osg::CullingSet& cs = clsb.getProjectionCullingStack().back();
|
osg::CullingSet& cs = clsb.getProjectionCullingStack().back();
|
||||||
cs.setFrustum(local_polytope);
|
cs.setFrustum(local_polytope);
|
||||||
|
|
||||||
clsb.pushCullingSet();
|
clsb.pushCullingSet();
|
||||||
|
|
||||||
_shadowedScene->accept(clsb);
|
_shadowedScene->accept(clsb);
|
||||||
@ -864,7 +883,7 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
|
|||||||
{
|
{
|
||||||
// OSG_NOTICE<<"Need to clamp projection matrix"<<std::endl;
|
// OSG_NOTICE<<"Need to clamp projection matrix"<<std::endl;
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
double xMid = (clsb._bb.xMin()+clsb._bb.xMax())*0.5f;
|
double xMid = (clsb._bb.xMin()+clsb._bb.xMax())*0.5f;
|
||||||
double xRange = clsb._bb.xMax()-clsb._bb.xMin();
|
double xRange = clsb._bb.xMax()-clsb._bb.xMin();
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user