First cut at LOD support in RayTracedTechnique, which lowers the number of samples taken when the view of the volume is changing.

This commit is contained in:
Robert Osfield 2011-03-17 11:49:22 +00:00
parent 127b103edd
commit 307bf7002f
2 changed files with 45 additions and 3 deletions

View File

@ -44,8 +44,15 @@ class OSGVOLUME_EXPORT RayTracedTechnique : public VolumeTechnique
protected:
virtual ~RayTracedTechnique();
osg::ref_ptr<osg::MatrixTransform> _transform;
typedef std::map<osgUtil::CullVisitor*, osg::Matrix> ModelViewMatrixMap;
OpenThreads::Mutex _mutex;
ModelViewMatrixMap _modelViewMatrixMap;
osg::ref_ptr<osg::StateSet> _lodStateSet;
};
}

View File

@ -534,6 +534,9 @@ void RayTracedTechnique::init()
}
_lodStateSet = new osg::StateSet;
_lodStateSet->addUniform(new osg::Uniform("SampleDensityValue",0.01f), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
}
void RayTracedTechnique::update(osgUtil::UpdateVisitor* uv)
@ -543,8 +546,40 @@ void RayTracedTechnique::update(osgUtil::UpdateVisitor* uv)
void RayTracedTechnique::cull(osgUtil::CullVisitor* cv)
{
//OSG_NOTICE<<"RayTracedTechnique::cull(osgUtil::CullVisitor* nv)"<<std::endl;
if (_transform.valid())
if (!_transform.valid()) return;
if (_lodStateSet.valid())
{
bool moving = false;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
ModelViewMatrixMap::iterator itr = _modelViewMatrixMap.find(cv);
if (itr!=_modelViewMatrixMap.end())
{
osg::Matrix newModelViewMatrix = *(cv->getModelViewMatrix());
osg::Matrix& previousModelViewMatrix = itr->second;
moving = (newModelViewMatrix != previousModelViewMatrix);
previousModelViewMatrix = newModelViewMatrix;
}
else
{
_modelViewMatrixMap[cv] = *(cv->getModelViewMatrix());
}
}
if (moving)
{
cv->pushStateSet(_lodStateSet.get());
_transform->accept(*cv);
cv->popStateSet();
}
else
{
_transform->accept(*cv);
}
}
else
{
_transform->accept(*cv);
}