2002-06-10 21:50:25 +08:00
|
|
|
#include <osg/CollectOccludersVisitor>
|
2002-06-12 03:52:55 +08:00
|
|
|
#include <osg/Transform>
|
|
|
|
#include <osg/Switch>
|
|
|
|
#include <osg/LOD>
|
|
|
|
#include <osg/OccluderNode>
|
|
|
|
#include <osg/Projection>
|
2002-06-10 21:50:25 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
CollectOccludersVisitor::CollectOccludersVisitor()
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
// overide the default node visitor mode.
|
|
|
|
setTraversalMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
|
2002-06-15 20:14:42 +08:00
|
|
|
|
2002-06-16 04:57:50 +08:00
|
|
|
setCullingMode(VIEW_FRUSTUM_CULLING|
|
2002-06-15 20:14:42 +08:00
|
|
|
NEAR_PLANE_CULLING|
|
|
|
|
FAR_PLANE_CULLING|
|
2002-06-16 04:57:50 +08:00
|
|
|
SMALL_FEATURE_CULLING);
|
2002-06-14 07:46:02 +08:00
|
|
|
|
2002-06-16 04:57:50 +08:00
|
|
|
_minimumShadowOccluderVolume = 0.01f;
|
2002-06-14 07:46:02 +08:00
|
|
|
_createDrawables = false;
|
|
|
|
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CollectOccludersVisitor::~CollectOccludersVisitor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::reset()
|
|
|
|
{
|
|
|
|
CullStack::reset();
|
|
|
|
}
|
|
|
|
|
2002-06-12 03:52:55 +08:00
|
|
|
void CollectOccludersVisitor::apply(osg::Node& node)
|
2002-06-10 21:50:25 +08:00
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
if (isCulled(node)) return;
|
|
|
|
|
|
|
|
// push the culling mode.
|
|
|
|
pushCurrentMask();
|
|
|
|
|
2002-06-14 21:49:59 +08:00
|
|
|
handle_cull_callbacks_and_traverse(node);
|
2002-06-12 03:52:55 +08:00
|
|
|
|
|
|
|
// pop the culling mode.
|
|
|
|
popCurrentMask();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::Transform& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
if (isCulled(node)) return;
|
|
|
|
|
|
|
|
// push the culling mode.
|
|
|
|
pushCurrentMask();
|
|
|
|
|
|
|
|
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(getModelViewMatrix());
|
|
|
|
node.getLocalToWorldMatrix(*matrix,this);
|
|
|
|
pushModelViewMatrix(matrix.get());
|
|
|
|
|
2002-06-14 21:49:59 +08:00
|
|
|
handle_cull_callbacks_and_traverse(node);
|
2002-06-12 03:52:55 +08:00
|
|
|
|
|
|
|
popModelViewMatrix();
|
|
|
|
|
|
|
|
// pop the culling mode.
|
|
|
|
popCurrentMask();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::Projection& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
if (isCulled(node)) return;
|
|
|
|
|
|
|
|
// push the culling mode.
|
|
|
|
pushCurrentMask();
|
|
|
|
|
|
|
|
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix(node.getMatrix());
|
|
|
|
pushProjectionMatrix(matrix.get());
|
|
|
|
|
2002-06-14 21:49:59 +08:00
|
|
|
handle_cull_callbacks_and_traverse(node);
|
2002-06-12 03:52:55 +08:00
|
|
|
|
|
|
|
popProjectionMatrix();
|
|
|
|
|
|
|
|
// pop the culling mode.
|
|
|
|
popCurrentMask();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::Switch& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
apply((Group&)node);
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::LOD& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
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;
|
2002-06-14 21:49:59 +08:00
|
|
|
handle_cull_callbacks_and_accept(node,node.getChild(eval));
|
2002-06-12 03:52:55 +08:00
|
|
|
|
|
|
|
// pop the culling mode.
|
|
|
|
popCurrentMask();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectOccludersVisitor::apply(osg::OccluderNode& node)
|
|
|
|
{
|
2002-06-12 03:52:55 +08:00
|
|
|
// need to check if occlusion node is in the occluder
|
|
|
|
// list, if so disable the appropriate ShadowOccluderVolume
|
|
|
|
disableOccluder(_nodePath);
|
|
|
|
|
|
|
|
|
|
|
|
if (isCulled(node)) return;
|
|
|
|
|
2002-06-14 00:21:00 +08:00
|
|
|
// std::cout<<"CollectOccludersVisitor:: We have found an Occlusion node in frustum"<<&node<<std::endl;
|
2002-06-12 17:22:30 +08:00
|
|
|
|
2002-06-12 03:52:55 +08:00
|
|
|
// push the culling mode.
|
|
|
|
pushCurrentMask();
|
|
|
|
|
2002-06-12 17:22:30 +08:00
|
|
|
|
2002-06-14 00:21:00 +08:00
|
|
|
if (node.getOccluder())
|
2002-06-12 17:22:30 +08:00
|
|
|
{
|
2002-06-14 00:21:00 +08:00
|
|
|
// computeOccluder will check if the occluder is the view frustum,
|
|
|
|
// if it ins't then the it will return false, when in it will
|
|
|
|
// clip the occluder's polygons in clip space, then create occluder
|
|
|
|
// planes, all with their normals facing inward towards the volume,
|
|
|
|
// and then transform them back into projection space.
|
|
|
|
ShadowVolumeOccluder svo;
|
2002-06-14 07:46:02 +08:00
|
|
|
if (svo.computeOccluder(_nodePath, *node.getOccluder(), *this,_createDrawables))
|
2002-06-14 00:21:00 +08:00
|
|
|
{
|
2002-06-15 20:14:42 +08:00
|
|
|
|
|
|
|
if (svo.getVolume()>_minimumShadowOccluderVolume)
|
|
|
|
{
|
|
|
|
// need to test occluder against view frustum.
|
|
|
|
std::cout << " adding in Occluder"<<std::endl;
|
|
|
|
_occluderList.push_back(svo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << " rejecting Occluder as its volume is too small "<<svo.getVolume()<<std::endl;
|
|
|
|
}
|
2002-06-14 00:21:00 +08:00
|
|
|
}
|
2002-06-12 17:22:30 +08:00
|
|
|
}
|
|
|
|
|
2002-06-14 21:49:59 +08:00
|
|
|
handle_cull_callbacks_and_traverse(node);
|
2002-06-12 03:52:55 +08:00
|
|
|
|
|
|
|
// pop the culling mode.
|
|
|
|
popCurrentMask();
|
2002-06-10 21:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|