Implemented ViewDependentShadowMap::setDebugDraw(bool) to allow osgshadow to enable/disable the debug display via the

standard --debugHUD option.
This commit is contained in:
Robert Osfield 2011-08-09 15:57:37 +00:00
parent c14516d5f6
commit 675a61ea87
3 changed files with 54 additions and 32 deletions

View File

@ -814,6 +814,7 @@ int main(int argc, char** argv)
else if( arguments.read("--vdsm") )
{
osg::ref_ptr<osgShadow::ViewDependentShadowMap> vdsm = new osgShadow::ViewDependentShadowMap;
while( arguments.read("--debugHUD") ) vdsm->setDebugDraw( true );
shadowedScene->setShadowTechnique(vdsm.get());
}
else /* if (arguments.read("--sm")) */
@ -829,8 +830,7 @@ int main(int argc, char** argv)
if( msm )// Set common MSM & LISPSM arguments
{
shadowedScene->setShadowTechnique( msm.get() );
while( arguments.read("--debugHUD") )
msm->setDebugDraw( true );
while( arguments.read("--debugHUD") ) msm->setDebugDraw( true );
float minLightMargin = 10.f;
float maxFarPlane = 0;

View File

@ -69,13 +69,17 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
osg::Vec3d frustumCenterLine;
};
// forward declare
class ViewDependentData;
struct OSGSHADOW_EXPORT LightData : public osg::Referenced
{
LightData();
LightData(ViewDependentData* vdd);
virtual void setLightData(osg::RefMatrix* lm, const osg::Light* l, const osg::Matrixd& modelViewMatrix);
bool active;
ViewDependentData* _viewDependentData;
osg::ref_ptr<osg::RefMatrix> lightMatrix;
osg::ref_ptr<const osg::Light> light;
@ -92,9 +96,10 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
struct OSGSHADOW_EXPORT ShadowData : public osg::Referenced
{
ShadowData();
ShadowData(ViewDependentData* vdd);
bool _active;
ViewDependentData* _viewDependentData;
unsigned int _textureUnit;
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osg::TexGen> _texgen;
@ -107,7 +112,9 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
class OSGSHADOW_EXPORT ViewDependentData : public osg::Referenced
{
public:
ViewDependentData();
ViewDependentData(ViewDependentShadowMap* vdsm);
const ViewDependentShadowMap* getViewDependentShadowMap() const { return _viewDependentShadowMap; }
LightDataList& getLightDataList() { return _lightDataList; }
@ -118,10 +125,12 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
protected:
virtual ~ViewDependentData() {}
ViewDependentShadowMap* _viewDependentShadowMap;
osg::ref_ptr<osg::StateSet> _stateset;
LightDataList _lightDataList;
ShadowDataList _shadowDataList;
LightDataList _lightDataList;
ShadowDataList _shadowDataList;
};
virtual ViewDependentData* createViewDependentData(osgUtil::CullVisitor* cv);
@ -131,7 +140,7 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
virtual void createShaders();
virtual bool selectActiveLights(osgUtil::CullVisitor* cv, LightDataList& pll) const;
virtual bool selectActiveLights(osgUtil::CullVisitor* cv, ViewDependentData* vdd) const;
virtual osg::Polytope computeLightViewFrustumPolytope(Frustum& frustum, LightData& positionedLight);
@ -145,6 +154,11 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
virtual osg::StateSet* selectStateSetForRenderingShadow(ViewDependentData& vdd) const;
void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; }
bool getDebugDraw() const { return _debugDraw; }
protected:
virtual ~ViewDependentShadowMap();
@ -153,6 +167,8 @@ protected:
ViewDependentDataMap _viewDependentDataMap;
osg::ref_ptr<osg::StateSet> _shadowRecievingPlaceholderStateSet;
bool _debugDraw;
};

View File

@ -116,8 +116,8 @@ void VDSMCameraCullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
//
// LightData
//
ViewDependentShadowMap::LightData::LightData():
active(false),
ViewDependentShadowMap::LightData::LightData(ViewDependentShadowMap::ViewDependentData* vdd):
_viewDependentData(vdd),
directionalLight(false)
{
}
@ -167,11 +167,11 @@ void ViewDependentShadowMap::LightData::setLightData(osg::RefMatrix* lm, const o
//
// ShadowData
//
ViewDependentShadowMap::ShadowData::ShadowData():
_active(false),
ViewDependentShadowMap::ShadowData::ShadowData(ViewDependentShadowMap::ViewDependentData* vdd):
_viewDependentData(vdd),
_textureUnit(0)
{
bool debug = false;
bool debug = vdd->getViewDependentShadowMap()->getDebugDraw();
// set up texgen
_texgen = new osg::TexGen;
@ -199,14 +199,17 @@ ViewDependentShadowMap::ShadowData::ShadowData():
// the shadow comparison should fail if object is outside the texture
_texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);
_texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);
_texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
//_texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
_texture->setBorderColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f));
// set up the camera
_camera = new osg::Camera;
_camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF_INHERIT_VIEWPOINT);
_camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
//_camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
_camera->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f));
//camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
// set viewport
@ -216,7 +219,7 @@ ViewDependentShadowMap::ShadowData::ShadowData():
if (debug)
{
// clear just the depth buffer
_camera->setClearMask(GL_DEPTH_BUFFER_BIT);
_camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
// render after the main camera
_camera->setRenderOrder(osg::Camera::POST_RENDER);
@ -369,7 +372,8 @@ ViewDependentShadowMap::Frustum::Frustum(osgUtil::CullVisitor* cv):
//
// ViewDependentData
//
ViewDependentShadowMap::ViewDependentData::ViewDependentData()
ViewDependentShadowMap::ViewDependentData::ViewDependentData(ViewDependentShadowMap* vdsm):
_viewDependentShadowMap(vdsm)
{
OSG_NOTICE<<"ViewDependentData::ViewDependentData()"<<this<<std::endl;
_stateset = new osg::StateSet;
@ -381,13 +385,15 @@ ViewDependentShadowMap::ViewDependentData::ViewDependentData()
// ViewDependentShadowMap
//
ViewDependentShadowMap::ViewDependentShadowMap():
ShadowTechnique()
ShadowTechnique(),
_debugDraw(false)
{
_shadowRecievingPlaceholderStateSet = new osg::StateSet;
}
ViewDependentShadowMap::ViewDependentShadowMap(const ViewDependentShadowMap& vdsm, const osg::CopyOp& copyop):
ShadowTechnique(vdsm,copyop)
ShadowTechnique(vdsm,copyop),
_debugDraw(vdsm._debugDraw)
{
_shadowRecievingPlaceholderStateSet = new osg::StateSet;
}
@ -415,7 +421,7 @@ void ViewDependentShadowMap::cleanSceneGraph()
ViewDependentShadowMap::ViewDependentData* ViewDependentShadowMap::createViewDependentData(osgUtil::CullVisitor* cv)
{
return new ViewDependentData();
return new ViewDependentData(this);
}
ViewDependentShadowMap::ViewDependentData* ViewDependentShadowMap::getViewDependentData(osgUtil::CullVisitor* cv)
@ -461,22 +467,20 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
// 2. select active light sources
// create a list of light sources + their matrices to place them
LightDataList& pll = vdd->getLightDataList();
selectActiveLights(&cv, pll);
selectActiveLights(&cv, vdd);
unsigned int pos_x = 0;
unsigned int baseTextureUnit = 0;
unsigned int textureUnit = baseTextureUnit;
unsigned int numValidShadows = 0;
bool debug = false;
Frustum frustum(&cv);
ShadowDataList& sdl = vdd->getShadowDataList();
ShadowDataList previous_sdl;
previous_sdl.swap(sdl);
LightDataList& pll = vdd->getLightDataList();
for(LightDataList::iterator itr = pll.begin();
itr != pll.end();
++itr)
@ -493,7 +497,7 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
if (previous_sdl.empty())
{
OSG_NOTICE<<"Create new ShadowData"<<std::endl;
sd = new ShadowData;
sd = new ShadowData(vdd);
}
else
{
@ -504,10 +508,10 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
osg::ref_ptr<osg::Camera> camera = sd->_camera;
if (debug)
if (_debugDraw)
{
camera->setViewport(pos_x,0,400,400);
pos_x += 440;
camera->getViewport()->x() = pos_x;
pos_x += camera->getViewport()->width() + 40;
}
osg::ref_ptr<osg::TexGen> texgen = sd->_texgen;
@ -575,10 +579,12 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
}
bool ViewDependentShadowMap::selectActiveLights(osgUtil::CullVisitor* cv, LightDataList& pll) const
bool ViewDependentShadowMap::selectActiveLights(osgUtil::CullVisitor* cv, ViewDependentData* vdd) const
{
OSG_NOTICE<<"selectActiveLights"<<std::endl;
LightDataList& pll = vdd->getLightDataList();
LightDataList previous_ldl;
previous_ldl.swap(pll);
@ -606,7 +612,7 @@ bool ViewDependentShadowMap::selectActiveLights(osgUtil::CullVisitor* cv, LightD
if (pll_itr==pll.end())
{
OSG_NOTICE<<"Light num "<<light->getLightNum()<<std::endl;
LightData* ld = new LightData();
LightData* ld = new LightData(vdd);
ld->setLightData(itr->second, light, modelViewMatrix);
pll.push_back(ld);
}