diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index e62dd6c8b..d929bb652 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -814,6 +814,7 @@ int main(int argc, char** argv) else if( arguments.read("--vdsm") ) { osg::ref_ptr 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; diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index 3d9d0e5dc..1ba7e8731 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -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 lightMatrix; osg::ref_ptr 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 _texture; osg::ref_ptr _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 _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 _shadowRecievingPlaceholderStateSet; + + bool _debugDraw; }; diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index 5cbec580d..dfddaa8ec 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -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()"<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"< 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 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"<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 "<getLightNum()<setLightData(itr->second, light, modelViewMatrix); pll.push_back(ld); }