A little more work on Occlusion culling.
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
#include <osg/CollectOccludersVisitor>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Switch>
|
||||
#include <osg/LOD>
|
||||
#include <osg/OccluderNode>
|
||||
#include <osg/Projection>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
CollectOccludersVisitor::CollectOccludersVisitor()
|
||||
{
|
||||
// overide the default node visitor mode.
|
||||
setTraversalMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
|
||||
}
|
||||
|
||||
CollectOccludersVisitor::~CollectOccludersVisitor()
|
||||
@@ -15,28 +22,96 @@ void CollectOccludersVisitor::reset()
|
||||
CullStack::reset();
|
||||
}
|
||||
|
||||
void CollectOccludersVisitor::apply(osg::Node&)
|
||||
void CollectOccludersVisitor::apply(osg::Node& node)
|
||||
{
|
||||
if (isCulled(node)) return;
|
||||
|
||||
// push the culling mode.
|
||||
pushCurrentMask();
|
||||
|
||||
traverse(node);
|
||||
|
||||
// pop the culling mode.
|
||||
popCurrentMask();
|
||||
}
|
||||
|
||||
void CollectOccludersVisitor::apply(osg::Transform& node)
|
||||
{
|
||||
if (isCulled(node)) return;
|
||||
|
||||
// push the culling mode.
|
||||
pushCurrentMask();
|
||||
|
||||
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
pushModelViewMatrix(matrix.get());
|
||||
|
||||
traverse(node);
|
||||
|
||||
popModelViewMatrix();
|
||||
|
||||
// pop the culling mode.
|
||||
popCurrentMask();
|
||||
}
|
||||
|
||||
void CollectOccludersVisitor::apply(osg::Projection& node)
|
||||
{
|
||||
if (isCulled(node)) return;
|
||||
|
||||
// push the culling mode.
|
||||
pushCurrentMask();
|
||||
|
||||
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
|
||||
pushProjectionMatrix(matrix.get());
|
||||
|
||||
traverse(node);
|
||||
|
||||
popProjectionMatrix();
|
||||
|
||||
// pop the culling mode.
|
||||
popCurrentMask();
|
||||
}
|
||||
|
||||
void CollectOccludersVisitor::apply(osg::Switch& node)
|
||||
{
|
||||
apply((Group&)node);
|
||||
}
|
||||
|
||||
void CollectOccludersVisitor::apply(osg::LOD& node)
|
||||
{
|
||||
if (isCulled(node)) return;
|
||||
|
||||
int eval = node.evaluate(getEyeLocal(),_LODBias);
|
||||
if (eval<0) return;
|
||||
|
||||
// push the culling mode.
|
||||
pushCurrentMask();
|
||||
|
||||
//notify(INFO) << "selecting child "<<eval<< std::endl;
|
||||
node.getChild(eval)->accept(*this);
|
||||
|
||||
// pop the culling mode.
|
||||
popCurrentMask();
|
||||
}
|
||||
|
||||
void CollectOccludersVisitor::apply(osg::OccluderNode& node)
|
||||
{
|
||||
// need to check if occlusion node is in the occluder
|
||||
// list, if so disable the appropriate ShadowOccluderVolume
|
||||
disableOccluder(_nodePath);
|
||||
|
||||
std::cout<<"CollectOccludersVisitor:: We have found an Occlusion node in frustum"<<&node<<std::endl;
|
||||
|
||||
|
||||
if (isCulled(node)) return;
|
||||
|
||||
// push the culling mode.
|
||||
pushCurrentMask();
|
||||
|
||||
traverse(node);
|
||||
|
||||
// pop the culling mode.
|
||||
popCurrentMask();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ CullStack::CullStack()
|
||||
{
|
||||
|
||||
_cullingMode = ENABLE_ALL_CULLING;
|
||||
_LODBias = 1.0f;
|
||||
_smallFeatureCullingPixelSize = 3.0f;
|
||||
|
||||
}
|
||||
|
||||
@@ -82,8 +82,6 @@ CullVisitor::CullVisitor()
|
||||
// overide the default node visitor mode.
|
||||
setTraversalMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
|
||||
|
||||
_LODBias = 1.0f;
|
||||
|
||||
//_tsm = LOOK_VECTOR_DISTANCE;
|
||||
_tsm = OBJECT_EYE_POINT_DISTANCE;
|
||||
|
||||
@@ -548,7 +546,7 @@ void CullVisitor::apply(osg::OccluderNode& node)
|
||||
// list, if so disable the appropriate ShadowOccluderVolume
|
||||
disableOccluder(_nodePath);
|
||||
|
||||
std::cout<<"We are in an Occlusion node"<<&node<<std::endl;
|
||||
std::cout<<"CullVisitor:: We are in an Occlusion node"<<&node<<std::endl;
|
||||
|
||||
|
||||
if (isCulled(node)) return;
|
||||
|
||||
Reference in New Issue
Block a user