A little more work on Occlusion culling.

This commit is contained in:
Robert Osfield
2002-06-11 19:52:55 +00:00
parent 247cb3ff7e
commit fa13d948b5
6 changed files with 83 additions and 9 deletions

View File

@@ -47,6 +47,7 @@ Ben Discoe <ben@vterrain.org>
Maroc Jez <marco.jez@arsenal.it>
- osgParticle
- IO support for osgText.
Byan Woods <byran@tapestrysolutions.com>
- Port to MacOS, various code changes to support this.

View File

@@ -54,6 +54,9 @@ class SG_EXPORT CullStack
void pushModelViewMatrix(osg::Matrix* matrix);
void popModelViewMatrix();
void setLODBias(const float bias) { _LODBias = bias; }
const float getLODBias() const { return _LODBias; }
void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; }
float& getSmallFeatureCullingPixelSize() { return _smallFeatureCullingPixelSize; }
float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
@@ -128,6 +131,7 @@ class SG_EXPORT CullStack
void popCullingSet();
CullingMode _cullingMode;
float _LODBias;
float _smallFeatureCullingPixelSize;
typedef fast_back_stack< ref_ptr<Matrix> > MatrixStack;

View File

@@ -67,9 +67,6 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
const osg::EarthSky* getEarthSky() const { return _earthSky.get(); }
void setLODBias(const float bias) { _LODBias = bias; }
const float getLODBias() const { return _LODBias; }
/** Switch the creation of Impostors on or off.
* Setting active to false forces the CullVisitor to use the Impostor
* LOD children for rendering. Setting active to true forces the
@@ -233,8 +230,6 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
RenderBin* _currentRenderBin;
float _LODBias;
ComputeNearFarMode _computeNearFar;
float _computed_znear;
float _computed_zfar;

View File

@@ -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();
}

View File

@@ -6,6 +6,7 @@ CullStack::CullStack()
{
_cullingMode = ENABLE_ALL_CULLING;
_LODBias = 1.0f;
_smallFeatureCullingPixelSize = 3.0f;
}

View File

@@ -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;