Added SampleRatioWhenMoving property and support to new osgVolume::MultipassTechnique.
This commit is contained in:
@@ -419,6 +419,12 @@ void MultipassTechnique::init()
|
||||
}
|
||||
|
||||
|
||||
if (cpv._sampleRatioWhenMovingProperty.valid())
|
||||
{
|
||||
_whenMovingStateSet = new osg::StateSet;
|
||||
_whenMovingStateSet->addUniform(cpv._sampleRatioWhenMovingProperty->getUniform(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MultipassTechnique::update(osgUtil::UpdateVisitor* /*uv*/)
|
||||
@@ -435,8 +441,18 @@ void MultipassTechnique::cull(osgUtil::CullVisitor* cv)
|
||||
|
||||
if (postTraversal)
|
||||
{
|
||||
// OSG_NOTICE<<" OK need to handle postTraversal"<<std::endl;
|
||||
_transform->accept(*cv);
|
||||
if (_whenMovingStateSet.valid() && isMoving(cv))
|
||||
{
|
||||
OSG_NOTICE<<"Using MovingStateSet"<<std::endl;
|
||||
cv->pushStateSet(_whenMovingStateSet.get());
|
||||
_transform->accept(*cv);
|
||||
cv->popStateSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"NOT using MovingStateSet"<<std::endl;
|
||||
_transform->accept(*cv);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -207,6 +207,20 @@ SampleRatioProperty::SampleRatioProperty(const SampleRatioProperty& srp,const os
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SampleRatioWhenMovingProperty
|
||||
//
|
||||
SampleRatioWhenMovingProperty::SampleRatioWhenMovingProperty(float value):
|
||||
ScalarProperty("SampleRatioValue",value)
|
||||
{
|
||||
}
|
||||
|
||||
SampleRatioWhenMovingProperty::SampleRatioWhenMovingProperty(const SampleRatioWhenMovingProperty& isp,const osg::CopyOp& copyop):
|
||||
ScalarProperty(isp, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -278,6 +292,7 @@ void CollectPropertiesVisitor::apply(LightingProperty& lp) { _lightingProperty =
|
||||
void CollectPropertiesVisitor::apply(SampleDensityProperty& sdp) { _sampleDensityProperty = &sdp; }
|
||||
void CollectPropertiesVisitor::apply(SampleDensityWhenMovingProperty& sdp) { _sampleDensityWhenMovingProperty = &sdp; }
|
||||
void CollectPropertiesVisitor::apply(SampleRatioProperty& srp) { _sampleRatioProperty = &srp; }
|
||||
void CollectPropertiesVisitor::apply(SampleRatioWhenMovingProperty& srp) { _sampleRatioWhenMovingProperty = &srp; }
|
||||
void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; }
|
||||
|
||||
|
||||
@@ -449,6 +464,13 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::
|
||||
OSG_NOTICE<<"Setting sample ratio to "<<sampleRatio<<std::endl;
|
||||
cpv._sampleRatioProperty->setValue(sampleRatio);
|
||||
}
|
||||
|
||||
if (_updateSampleDensity && cpv._sampleRatioWhenMovingProperty.valid())
|
||||
{
|
||||
float sampleRatio = v2*4;
|
||||
OSG_NOTICE<<"Setting sample ratio to "<<sampleRatio<<std::endl;
|
||||
cpv._sampleRatioWhenMovingProperty->setValue(sampleRatio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -498,36 +498,11 @@ void RayTracedTechnique::cull(osgUtil::CullVisitor* cv)
|
||||
{
|
||||
if (!_transform.valid()) return;
|
||||
|
||||
if (_whenMovingStateSet.valid())
|
||||
if (_whenMovingStateSet.valid() && isMoving(cv))
|
||||
{
|
||||
bool moving = false;
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
ModelViewMatrixMap::iterator itr = _modelViewMatrixMap.find(cv->getIdentifier());
|
||||
if (itr!=_modelViewMatrixMap.end())
|
||||
{
|
||||
osg::Matrix newModelViewMatrix = *(cv->getModelViewMatrix());
|
||||
osg::Matrix& previousModelViewMatrix = itr->second;
|
||||
moving = (newModelViewMatrix != previousModelViewMatrix);
|
||||
|
||||
previousModelViewMatrix = newModelViewMatrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
_modelViewMatrixMap[cv->getIdentifier()] = *(cv->getModelViewMatrix());
|
||||
}
|
||||
}
|
||||
|
||||
if (moving)
|
||||
{
|
||||
cv->pushStateSet(_whenMovingStateSet.get());
|
||||
_transform->accept(*cv);
|
||||
cv->popStateSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
_transform->accept(*cv);
|
||||
}
|
||||
cv->pushStateSet(_whenMovingStateSet.get());
|
||||
_transform->accept(*cv);
|
||||
cv->popStateSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -86,3 +86,27 @@ void VolumeTechnique::traverse(osg::NodeVisitor& nv)
|
||||
// otherwise fallback to the Group::traverse()
|
||||
_volumeTile->osg::Group::traverse(nv);
|
||||
}
|
||||
|
||||
bool VolumeTechnique::isMoving(osgUtil::CullVisitor* cv)
|
||||
{
|
||||
bool moving = false;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
|
||||
OSG_NOTICE<<"cv="<<cv<<", cv->getIdentifier()="<<cv->getIdentifier()<<std::endl;
|
||||
|
||||
ModelViewMatrixMap::iterator itr = _modelViewMatrixMap.find(cv->getIdentifier());
|
||||
if (itr!=_modelViewMatrixMap.end())
|
||||
{
|
||||
osg::Matrix newModelViewMatrix = *(cv->getModelViewMatrix());
|
||||
osg::Matrix& previousModelViewMatrix = itr->second;
|
||||
moving = (newModelViewMatrix != previousModelViewMatrix);
|
||||
|
||||
previousModelViewMatrix = newModelViewMatrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
_modelViewMatrixMap[cv->getIdentifier()] = *(cv->getModelViewMatrix());
|
||||
}
|
||||
return moving;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user