Flesh out more of basic ShadowTechnique and ShadowedScene API.
This commit is contained in:
parent
47622e6134
commit
95befaf1ed
@ -23,6 +23,8 @@
|
|||||||
#include <osgViewer/StatsHandler>
|
#include <osgViewer/StatsHandler>
|
||||||
|
|
||||||
#include <osgShadow/OccluderGeometry>
|
#include <osgShadow/OccluderGeometry>
|
||||||
|
#include <osgShadow/ShadowedScene>
|
||||||
|
#include <osgShadow/ShadowVolume>
|
||||||
|
|
||||||
#include <osgDB/ReadFile>
|
#include <osgDB/ReadFile>
|
||||||
#include <osgDB/WriteFile>
|
#include <osgDB/WriteFile>
|
||||||
@ -566,6 +568,9 @@ int main(int argc, char** argv)
|
|||||||
while (arguments.read("--two-sided")) drawMode = osgShadow::ShadowVolumeGeometry::STENCIL_TWO_SIDED;
|
while (arguments.read("--two-sided")) drawMode = osgShadow::ShadowVolumeGeometry::STENCIL_TWO_SIDED;
|
||||||
while (arguments.read("--two-pass")) drawMode = osgShadow::ShadowVolumeGeometry::STENCIL_TWO_PASS;
|
while (arguments.read("--two-pass")) drawMode = osgShadow::ShadowVolumeGeometry::STENCIL_TWO_PASS;
|
||||||
|
|
||||||
|
bool ShadowVolume = false;
|
||||||
|
while (arguments.read("--ShadowVolume")) ShadowVolume = true;
|
||||||
|
|
||||||
|
|
||||||
// set up the camera manipulators.
|
// set up the camera manipulators.
|
||||||
{
|
{
|
||||||
@ -680,7 +685,17 @@ int main(int argc, char** argv)
|
|||||||
osg::ref_ptr<osg::Light> light = new osg::Light;
|
osg::ref_ptr<osg::Light> light = new osg::Light;
|
||||||
light->setPosition(lightpos);
|
light->setPosition(lightpos);
|
||||||
|
|
||||||
if (!doShadow)
|
if (ShadowVolume)
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene;
|
||||||
|
|
||||||
|
shadowedScene->setShadowTechnique(new osgShadow::ShadowVolume);
|
||||||
|
|
||||||
|
shadowedScene->addChild(model.get());
|
||||||
|
|
||||||
|
group->addChild(shadowedScene.get());
|
||||||
|
}
|
||||||
|
else if (!doShadow)
|
||||||
{
|
{
|
||||||
group->addChild(model.get());
|
group->addChild(model.get());
|
||||||
|
|
||||||
|
@ -36,10 +36,27 @@ class OSGSHADOW_EXPORT ShadowTechnique : public osg::Object
|
|||||||
|
|
||||||
META_Object(osgShadow, ShadowTechnique);
|
META_Object(osgShadow, ShadowTechnique);
|
||||||
|
|
||||||
|
ShadowedScene* getShadowedScene() { return _shadowedScene; }
|
||||||
|
|
||||||
|
virtual void init();
|
||||||
|
|
||||||
|
virtual void update(osg::NodeVisitor& nv);
|
||||||
|
|
||||||
|
virtual void cull(osg::NodeVisitor& nv);
|
||||||
|
|
||||||
|
virtual void traverse(osg::NodeVisitor& nv);
|
||||||
|
|
||||||
|
virtual void dirty() { _dirty = true; }
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
virtual ~ShadowTechnique() {}
|
virtual ~ShadowTechnique() {}
|
||||||
|
|
||||||
|
friend class ShadowedScene;
|
||||||
|
|
||||||
|
ShadowedScene* _shadowedScene;
|
||||||
|
bool _dirty;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ namespace osgShadow {
|
|||||||
class OSGSHADOW_EXPORT ShadowedScene : public osg::Group
|
class OSGSHADOW_EXPORT ShadowedScene : public osg::Group
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ShadowedScene();
|
ShadowedScene();
|
||||||
|
|
||||||
ShadowedScene(const ShadowedScene& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
ShadowedScene(const ShadowedScene& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||||
@ -45,10 +46,12 @@ class OSGSHADOW_EXPORT ShadowedScene : public osg::Group
|
|||||||
ShadowTechnique* getShadowTechnique() { return _shadowTechnique.get(); }
|
ShadowTechnique* getShadowTechnique() { return _shadowTechnique.get(); }
|
||||||
const ShadowTechnique* getShadowTechnique() const { return _shadowTechnique.get(); }
|
const ShadowTechnique* getShadowTechnique() const { return _shadowTechnique.get(); }
|
||||||
|
|
||||||
|
/** Dirty any cache data structures held in the attached ShadowTechnqiue.*/
|
||||||
|
void dirty();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual ~ShadowedScene() {}
|
virtual ~ShadowedScene();
|
||||||
|
|
||||||
unsigned int _recievesShadowTraversalMask;
|
unsigned int _recievesShadowTraversalMask;
|
||||||
unsigned int _castsShadowTraversalMask;
|
unsigned int _castsShadowTraversalMask;
|
||||||
|
@ -12,14 +12,59 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <osgShadow/ShadowTechnique>
|
#include <osgShadow/ShadowTechnique>
|
||||||
|
#include <osgShadow/ShadowedScene>
|
||||||
|
#include <osg/Notify>
|
||||||
|
|
||||||
using namespace osgShadow;
|
using namespace osgShadow;
|
||||||
|
|
||||||
ShadowTechnique::ShadowTechnique()
|
ShadowTechnique::ShadowTechnique():
|
||||||
|
_shadowedScene(0),
|
||||||
|
_dirty(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ShadowTechnique::ShadowTechnique(const ShadowTechnique& copy, const osg::CopyOp& copyop):
|
ShadowTechnique::ShadowTechnique(const ShadowTechnique& copy, const osg::CopyOp& copyop):
|
||||||
osg::Object(copy,copyop)
|
osg::Object(copy,copyop),
|
||||||
|
_shadowedScene(0),
|
||||||
|
_dirty(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShadowTechnique::init()
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<className()<<"::init() not implemened yet"<<std::endl;
|
||||||
|
|
||||||
|
_dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShadowTechnique::update(osg::NodeVisitor& nv)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<className()<<"::update(osg::NodeVisitor&) not implemened yet."<<std::endl;
|
||||||
|
_shadowedScene->osg::Group::traverse(nv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShadowTechnique::cull(osg::NodeVisitor& nv)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<className()<<"::cull(osg::NodeVisitor&) not implemened yet."<<std::endl;
|
||||||
|
_shadowedScene->osg::Group::traverse(nv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShadowTechnique::traverse(osg::NodeVisitor& nv)
|
||||||
|
{
|
||||||
|
if (!_shadowedScene) return;
|
||||||
|
|
||||||
|
if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||||
|
{
|
||||||
|
if (_dirty) init();
|
||||||
|
|
||||||
|
update(nv);
|
||||||
|
}
|
||||||
|
else if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
|
||||||
|
{
|
||||||
|
cull(nv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_shadowedScene->osg::Group::traverse(nv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -32,26 +32,42 @@ ShadowedScene::ShadowedScene(const ShadowedScene& copy, const osg::CopyOp& copyo
|
|||||||
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShadowedScene::~ShadowedScene()
|
||||||
|
{
|
||||||
|
setShadowTechnique(0);
|
||||||
|
}
|
||||||
|
|
||||||
void ShadowedScene::traverse(osg::NodeVisitor& nv)
|
void ShadowedScene::traverse(osg::NodeVisitor& nv)
|
||||||
{
|
{
|
||||||
if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
if (_shadowTechnique.valid())
|
||||||
{
|
{
|
||||||
Group::traverse(nv);
|
_shadowTechnique->traverse(nv);
|
||||||
return;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
osg::Group::traverse(nv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nv.getVisitorType() != osg::NodeVisitor::CULL_VISITOR)
|
void ShadowedScene::setShadowTechnique(ShadowTechnique* technique)
|
||||||
{
|
{
|
||||||
Group::traverse(nv);
|
if (_shadowTechnique == technique) return;
|
||||||
return;
|
|
||||||
|
if (_shadowTechnique.valid()) _shadowTechnique->_shadowedScene = 0;
|
||||||
|
|
||||||
|
_shadowTechnique = technique;
|
||||||
|
|
||||||
|
if (_shadowTechnique.valid())
|
||||||
|
{
|
||||||
|
_shadowTechnique->_shadowedScene = this;
|
||||||
|
_shadowTechnique->dirty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
|
void ShadowedScene::dirty()
|
||||||
if (!cv)
|
|
||||||
{
|
{
|
||||||
Group::traverse(nv);
|
if (_shadowTechnique.valid())
|
||||||
return;
|
{
|
||||||
|
_shadowTechnique->dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
Group::traverse(nv);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user