Added _maximumNumberOfActiveOccluders variable to CollectOccludersVisitor(), to
limit the maximum number of occluders used in the cull traversal, default is now 10. Added set/getCollectOccluderVisitor() method into SceneView to allow control of the the settings of the CollectOccluderVisitor.
This commit is contained in:
@@ -46,10 +46,15 @@ class SG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::C
|
||||
virtual void apply(osg::LOD& node);
|
||||
virtual void apply(osg::OccluderNode& node);
|
||||
|
||||
|
||||
/** Set the minimum shadow occluder volume that an active occluder must have.
|
||||
* volume is units relative the clip space volume where 1.0 is the whole clip space.*/
|
||||
void setMinimumShadowOccluderVolume(float vol) { _minimumShadowOccluderVolume = vol; }
|
||||
float getMinimumShadowOccluderVolume() const { return _minimumShadowOccluderVolume; }
|
||||
|
||||
/** Set the maximum number of occluders to have active for culling purposes.*/
|
||||
void setMaximumNumberOfActiveOccluders(unsigned int num) { _maximumNumberOfActiveOccluders = num; }
|
||||
unsigned int getMaximumNumberOfActiveOccluders() const { return _maximumNumberOfActiveOccluders; }
|
||||
|
||||
void setCreateDrawablesOnOccludeNodes(bool flag) { _createDrawables=flag; }
|
||||
bool getCreateDrawablesOnOccludeNodes() const { return _createDrawables; }
|
||||
|
||||
@@ -57,7 +62,9 @@ class SG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::C
|
||||
ShadowVolumeOccluderSet& getCollectedOccluderSet() { return _occluderSet; }
|
||||
const ShadowVolumeOccluderSet& getCollectedOccluderSet() const { return _occluderSet; }
|
||||
|
||||
/** remove occluded occluders for the collected occluders list.*/
|
||||
/** remove occluded occluders for the collected occluders list,
|
||||
* and then discard of all but MaximumNumberOfActiveOccluders of occluders,
|
||||
* discarding the occluders with the lowests shadow occluder volume .*/
|
||||
void removeOccludedOccluders();
|
||||
|
||||
|
||||
@@ -84,6 +91,7 @@ class SG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::C
|
||||
}
|
||||
|
||||
float _minimumShadowOccluderVolume;
|
||||
unsigned _maximumNumberOfActiveOccluders;
|
||||
bool _createDrawables;
|
||||
ShadowVolumeOccluderSet _occluderSet;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <osg/Light>
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/DisplaySettings>
|
||||
#include <osg/CollectOccludersVisitor>
|
||||
|
||||
|
||||
#include <osgUtil/CullVisitor>
|
||||
@@ -234,6 +235,10 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
void setCullVisitorRight(osgUtil::CullVisitor* cv) { _cullVisitorRight = cv; }
|
||||
osgUtil::CullVisitor* getCullVisitorRight() { return _cullVisitorRight.get(); }
|
||||
const osgUtil::CullVisitor* getCullVisitorRight() const { return _cullVisitorRight.get(); }
|
||||
|
||||
void setCollectOccludersVisitor(osg::CollectOccludersVisitor* cov) { _collectOccludersVisistor = cov; }
|
||||
osg::CollectOccludersVisitor* getCollectOccludersVisitor() { return _collectOccludersVisistor.get(); }
|
||||
const osg::CollectOccludersVisitor* getCollectOccludersVisitor() const { return _collectOccludersVisistor.get(); }
|
||||
|
||||
|
||||
void setRenderGraph(osgUtil::RenderGraph* rg) { _rendergraph = rg; }
|
||||
@@ -465,8 +470,11 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
osg::ref_ptr<osgUtil::RenderGraph> _rendergraphRight;
|
||||
osg::ref_ptr<osgUtil::RenderStage> _renderStageRight;
|
||||
|
||||
osg::ref_ptr<osg::CollectOccludersVisitor> _collectOccludersVisistor;
|
||||
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
|
||||
|
||||
osg::Vec4 _backgroundColor;
|
||||
|
||||
CullVisitor::ComputeNearFarMode _computeNearFar;
|
||||
|
||||
@@ -31,6 +31,7 @@ CollectOccludersVisitor::CollectOccludersVisitor():
|
||||
SMALL_FEATURE_CULLING);
|
||||
|
||||
_minimumShadowOccluderVolume = 0.005f;
|
||||
_maximumNumberOfActiveOccluders = 10;
|
||||
_createDrawables = false;
|
||||
|
||||
}
|
||||
@@ -42,6 +43,7 @@ CollectOccludersVisitor::~CollectOccludersVisitor()
|
||||
void CollectOccludersVisitor::reset()
|
||||
{
|
||||
CullStack::reset();
|
||||
_occluderSet.clear();
|
||||
}
|
||||
|
||||
float CollectOccludersVisitor::getDistanceToEyePoint(const Vec3& pos, bool withLODScale) const
|
||||
@@ -236,4 +238,16 @@ void CollectOccludersVisitor::removeOccludedOccluders()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_occluderSet.size()<=_maximumNumberOfActiveOccluders) return;
|
||||
|
||||
// move the iterator to the _maximumNumberOfActiveOccluders th occluder.
|
||||
occludeeItr = _occluderSet.begin();
|
||||
for(unsigned int i=0;i<_maximumNumberOfActiveOccluders;++i)
|
||||
++occludeeItr;
|
||||
|
||||
// discard last occluders.
|
||||
_occluderSet.erase(occludeeItr,_occluderSet.end());
|
||||
|
||||
}
|
||||
|
||||
@@ -449,35 +449,38 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
|
||||
{
|
||||
//std::cout << "Scene graph contains occluder nodes, searching for them"<<std::endl;
|
||||
|
||||
osg::CollectOccludersVisitor cov;
|
||||
|
||||
cov.setFrameStamp(_frameStamp.get());
|
||||
if (!_collectOccludersVisistor) _collectOccludersVisistor = new osg::CollectOccludersVisitor;
|
||||
|
||||
_collectOccludersVisistor->reset();
|
||||
|
||||
_collectOccludersVisistor->setFrameStamp(_frameStamp.get());
|
||||
|
||||
// use the frame number for the traversal number.
|
||||
if (_frameStamp.valid())
|
||||
{
|
||||
cov.setTraversalNumber(_frameStamp->getFrameNumber());
|
||||
_collectOccludersVisistor->setTraversalNumber(_frameStamp->getFrameNumber());
|
||||
}
|
||||
|
||||
cov.pushViewport(_viewport.get());
|
||||
cov.pushProjectionMatrix(proj.get());
|
||||
cov.pushModelViewMatrix(mv.get());
|
||||
_collectOccludersVisistor->pushViewport(_viewport.get());
|
||||
_collectOccludersVisistor->pushProjectionMatrix(proj.get());
|
||||
_collectOccludersVisistor->pushModelViewMatrix(mv.get());
|
||||
|
||||
// traverse the scene graph to search for occluder in there new positions.
|
||||
_sceneData->accept(cov);
|
||||
_sceneData->accept(*_collectOccludersVisistor);
|
||||
|
||||
cov.popModelViewMatrix();
|
||||
cov.popProjectionMatrix();
|
||||
cov.popViewport();
|
||||
_collectOccludersVisistor->popModelViewMatrix();
|
||||
_collectOccludersVisistor->popProjectionMatrix();
|
||||
_collectOccludersVisistor->popViewport();
|
||||
|
||||
// sort the occluder from largest occluder volume to smallest.
|
||||
cov.removeOccludedOccluders();
|
||||
_collectOccludersVisistor->removeOccludedOccluders();
|
||||
|
||||
|
||||
//std::cout << "finished searching for occluder - found "<<cov.getCollectedOccluderSet().size()<<std::endl;
|
||||
osg::notify(osg::INFO) << "finished searching for occluder - found "<<_collectOccludersVisistor->getCollectedOccluderSet().size()<<std::endl;
|
||||
|
||||
cullVisitor->getOccluderList().clear();
|
||||
std::copy(cov.getCollectedOccluderSet().begin(),cov.getCollectedOccluderSet().end(), std::back_insert_iterator<CullStack::OccluderList>(cullVisitor->getOccluderList()));
|
||||
std::copy(_collectOccludersVisistor->getCollectedOccluderSet().begin(),_collectOccludersVisistor->getCollectedOccluderSet().end(), std::back_insert_iterator<CullStack::OccluderList>(cullVisitor->getOccluderList()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user