diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index 8675e4c35..c930b5c75 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -598,7 +598,6 @@ namespace ModelFive osg::Geometry* geometry = dynamic_cast(geode.getDrawable(i)); if (geometry) { - OSG_NOTICE<<"geometry->setUseVertexBufferObjects(true);"<setUseVertexBufferObjects(true); } } @@ -641,6 +640,16 @@ namespace ModelFive cessnaNode->addUpdateCallback( createAnimationPathCallback(50.0f, 6.0f) ); cessnaNode->setNodeMask( CastsShadowTraversalMask ); + // cessna is really poorly optimized so fix this by optimizing the mesh and use VBO's. + osgUtil::Optimizer optimizer; + optimizer.optimize(cessnaNode.get(), osgUtil::Optimizer::INDEX_MESH | + osgUtil::Optimizer::VERTEX_POSTTRANSFORM | + osgUtil::Optimizer::VERTEX_PRETRANSFORM); + + UseVBOVisitor useVBOVisitor; + cessnaNode->accept(useVBOVisitor); + + osg::ref_ptr shadowRoot = new osg::Group; shadowRoot->addChild( groundNode.get() ); for ( unsigned int i=0; i<10; ++i ) @@ -654,14 +663,6 @@ namespace ModelFive } } - // cessna is really poorly optimized so fix this by optimizing the mesh and use VBO's. - osgUtil::Optimizer optimizer; - optimizer.optimize(shadowRoot.get(), osgUtil::Optimizer::INDEX_MESH | - osgUtil::Optimizer::VERTEX_POSTTRANSFORM | - osgUtil::Optimizer::VERTEX_PRETRANSFORM); - - UseVBOVisitor useVBOVisitor; - shadowRoot->accept(useVBOVisitor); return shadowRoot.release(); } @@ -917,18 +918,20 @@ 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 ); + osgShadow::ShadowSettings* settings = new osgShadow::ShadowSettings; + shadowedScene->setShadowSettings(settings); - if (arguments.read("--persp")) vdsm->setShadowMapProjectionHint(osgShadow::ViewDependentShadowMap::PERSPECTIVE_SHADOW_MAP); - if (arguments.read("--ortho")) vdsm->setShadowMapProjectionHint(osgShadow::ViewDependentShadowMap::ORTHOGRAPHIC_SHADOW_MAP); + while( arguments.read("--debugHUD") ) settings->setDebugDraw( true ); + if (arguments.read("--persp")) settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::PERSPECTIVE_SHADOW_MAP); + if (arguments.read("--ortho")) settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::ORTHOGRAPHIC_SHADOW_MAP); unsigned int unit=1; - if (arguments.read("--unit",unit)) vdsm->setBaseShadowTextureUnit(unit); + if (arguments.read("--unit",unit)) settings->setBaseShadowTextureUnit(unit); double n=0.0; - if (arguments.read("-n",n)) vdsm->setMinimumShadowMapNearFarRatio(n); + if (arguments.read("-n",n)) settings->setMinimumShadowMapNearFarRatio(n); + osg::ref_ptr vdsm = new osgShadow::ViewDependentShadowMap; shadowedScene->setShadowTechnique(vdsm.get()); } else if ( arguments.read("--lispsm") ) diff --git a/include/osgShadow/ShadowSettings b/include/osgShadow/ShadowSettings new file mode 100644 index 000000000..db9354147 --- /dev/null +++ b/include/osgShadow/ShadowSettings @@ -0,0 +1,96 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-20 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGSHADOW_SHADOWSETTINGS +#define OSGSHADOW_SHADOWSETTINGS 1 + +#include +#include + +namespace osgShadow { + +/** ShadowSettings provides the parameters that the ShadowTechnique should use as a guide for setting up shadowing.*/ +class OSGSHADOW_EXPORT ShadowSettings : public osg::Object +{ + public: + ShadowSettings(); + ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgShadow, ShadowSettings); + + void setLightNum(unsigned int lightNum) { _lightNum = lightNum; } + unsigned int getLightNum() const { return _lightNum; } + + void setBaseShadowTextureUnit(unsigned int unit) { _baseShadowTextureUnit = unit; } + unsigned int getBaseShadowTextureUnit() const { return _baseShadowTextureUnit; } + + + /** Set the size of the shadow map textures.*/ + void setTextureSize(const osg::Vec2s& textureSize) { _textureSize = textureSize; } + + /** Get the size of the shadow map textures.*/ + const osg::Vec2s& getTextureSize() const { return _textureSize; } + + void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; } + double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; } + + enum ShadowMapProjectionHint + { + ORTHOGRAPHIC_SHADOW_MAP, + PERSPECTIVE_SHADOW_MAP + }; + + void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; } + ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; } + + /** Set the cut off angle, in degrees, between the light direction and the view direction + * that determines whether perspective shadow mapping is appropriate, or thar orthographic shadow + * map should be used instead. Default is 2 degrees so that for any angle greater than 2 degrees + * perspective shadow map will be used, and any angle less than 2 degrees orthographic shadow map + * will be used. Note, if ShadowMapProjectionHint is set to ORTHOGRAPHIC_SHADOW_MAP then an + * orthographic shadow map will always be used.*/ + void setPerspectiveShadowMapCutOffAngle(double angle) { _perspectiveShadowMapCutOffAngle = angle; } + double getPerspectiveShadowMapCutOffAngle() const { return _perspectiveShadowMapCutOffAngle; } + + enum ShaderHint + { + NO_SHADERS, + PROVIDE_FRAGMENT_SHADER, + PROVIDE_VERTEX_AND_FRAGMENT_SHADER + }; + + void setShaderHint(ShaderHint shaderHint) { _shaderHint = shaderHint; } + ShaderHint getShaderHint() const { return _shaderHint; } + + void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; } + bool getDebugDraw() const { return _debugDraw; } + + protected: + + virtual ~ShadowSettings(); + + unsigned int _lightNum; + unsigned int _baseShadowTextureUnit; + osg::Vec2s _textureSize; + + double _minimumShadowMapNearFarRatio; + ShadowMapProjectionHint _shadowMapProjectionHint; + double _perspectiveShadowMapCutOffAngle; + ShaderHint _shaderHint; + bool _debugDraw; + +}; + +} + +#endif \ No newline at end of file diff --git a/include/osgShadow/ShadowTechnique b/include/osgShadow/ShadowTechnique index b67bc6e94..10fdc38f9 100644 --- a/include/osgShadow/ShadowTechnique +++ b/include/osgShadow/ShadowTechnique @@ -38,6 +38,8 @@ class OSGSHADOW_EXPORT ShadowTechnique : public osg::Object META_Object(osgShadow, ShadowTechnique); ShadowedScene* getShadowedScene() { return _shadowedScene; } + + const ShadowedScene* getShadowedScene() const { return _shadowedScene; } /** initialize the ShadowedScene and local cached data structures.*/ virtual void init(); diff --git a/include/osgShadow/ShadowedScene b/include/osgShadow/ShadowedScene index e2b5cf2e5..194976490 100644 --- a/include/osgShadow/ShadowedScene +++ b/include/osgShadow/ShadowedScene @@ -20,6 +20,7 @@ #include #include +#include namespace osgShadow { @@ -42,6 +43,10 @@ class OSGSHADOW_EXPORT ShadowedScene : public osg::Group void setCastsShadowTraversalMask(unsigned int mask) { _castsShadowTraversalMask = mask; } unsigned int getCastsShadowTraversalMask() const { return _castsShadowTraversalMask; } + void setShadowSettings(ShadowSettings* ss); + ShadowSettings* getShadowSettings() { return _shadowSettings.get(); } + const ShadowSettings* getShadowSettings() const { return _shadowSettings.get(); } + void setShadowTechnique(ShadowTechnique* technique); ShadowTechnique* getShadowTechnique() { return _shadowTechnique.get(); } const ShadowTechnique* getShadowTechnique() const { return _shadowTechnique.get(); } @@ -66,8 +71,9 @@ protected: unsigned int _receivesShadowTraversalMask; unsigned int _castsShadowTraversalMask; - - osg::ref_ptr _shadowTechnique; + + osg::ref_ptr _shadowSettings; + osg::ref_ptr _shadowTechnique; }; diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index a923f5245..d8d11a8ec 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-20011 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -152,49 +152,6 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique ViewDependentData* getViewDependentData(osgUtil::CullVisitor* cv); - /** Set the texture unit that the first shadow map will be placed on, if mulitple shadow maps are - * required then each shadow map will use a allocated a unit relative to this base texture unit.*/ - void setBaseShadowTextureUnit(unsigned int unit) { _baseShadowTextureUnit = unit; } - - /** Get the texture unit that the first shadow map will be placed on.*/ - unsigned int getBaseShadowTextureUnit() const { return _baseShadowTextureUnit; } - - /** Set the size of the shadow map textures.*/ - void setTextureSize(const osg::Vec2s& textureSize) { _textureSize = textureSize; } - - /** Get the size of the shadow map textures.*/ - const osg::Vec2s& getTextureSize() const { return _textureSize; } - - void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; } - double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; } - - enum ShadowMapProjectionHint - { - ORTHOGRAPHIC_SHADOW_MAP, - PERSPECTIVE_SHADOW_MAP - }; - - void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; } - ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; } - - /** Set the cut off angle, in degrees, between the light direction and the view direction - * that determines whether perspective shadow mapping is appropriate, or thar orthographic shadow - * map should be used instead. Default is 2 degrees so that for any angle greater than 2 degrees - * perspective shadow map will be used, and any angle less than 2 degrees orthographic shadow map - * will be used. Note, if ShadowMapProjectionHint is set to ORTHOGRAPHIC_SHADOW_MAP then an - * orthographic shadow map will always be used.*/ - void setPerspectiveShadowMapCutOffAngle(double angle) { _perspectiveShadowMapCutOffAngle = angle; } - double getPerspectiveShadowMapCutOffAngle() const { return _perspectiveShadowMapCutOffAngle; } - - enum ShaderHint - { - NO_SHADERS, - PROVIDE_FRAGMENT_SHADER, - PROVIDE_VERTEX_AND_FRAGMENT_SHADER - }; - - void setShaderHint(ShaderHint shaderHint) { _shaderHint = shaderHint; } - ShaderHint getShaderHint() const { return _shaderHint; } virtual void createShaders(); @@ -214,10 +171,6 @@ 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(); @@ -226,9 +179,6 @@ protected: mutable OpenThreads::Mutex _viewDependentDataMapMutex; ViewDependentDataMap _viewDependentDataMap; - unsigned int _baseShadowTextureUnit; - osg::Vec2s _textureSize; - osg::ref_ptr _shadowRecievingPlaceholderStateSet; osg::ref_ptr _shadowCastingStateSet; @@ -239,13 +189,6 @@ protected: typedef std::vector< osg::ref_ptr > Uniforms; Uniforms _uniforms; osg::ref_ptr _program; - - double _minimumShadowMapNearFarRatio; - ShadowMapProjectionHint _shadowMapProjectionHint; - double _perspectiveShadowMapCutOffAngle; - ShaderHint _shaderHint; - bool _debugDraw; - }; } diff --git a/src/osgShadow/CMakeLists.txt b/src/osgShadow/CMakeLists.txt index 40cee5de4..2dcd76985 100644 --- a/src/osgShadow/CMakeLists.txt +++ b/src/osgShadow/CMakeLists.txt @@ -15,6 +15,7 @@ SET(TARGET_H ${HEADER_PATH}/ShadowTexture ${HEADER_PATH}/ShadowVolume ${HEADER_PATH}/ShadowedScene + ${HEADER_PATH}/ShadowSettings ${HEADER_PATH}/SoftShadowMap ${HEADER_PATH}/ParallelSplitShadowMap ${HEADER_PATH}/Version @@ -38,6 +39,7 @@ SET(TARGET_SRC ShadowTexture.cpp ShadowVolume.cpp ShadowedScene.cpp + ShadowSettings.cpp SoftShadowMap.cpp ParallelSplitShadowMap.cpp Version.cpp diff --git a/src/osgShadow/ShadowSettings.cpp b/src/osgShadow/ShadowSettings.cpp new file mode 100644 index 000000000..e8ecdcf70 --- /dev/null +++ b/src/osgShadow/ShadowSettings.cpp @@ -0,0 +1,44 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2011 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + +using namespace osgShadow; + +ShadowSettings::ShadowSettings(): + _baseShadowTextureUnit(1), + _textureSize(2048,2048), + _minimumShadowMapNearFarRatio(0.01), + _shadowMapProjectionHint(PERSPECTIVE_SHADOW_MAP), + _perspectiveShadowMapCutOffAngle(2.0), + _shaderHint(NO_SHADERS), +// _shaderHint(PROVIDE_FRAGMENT_SHADER), + _debugDraw(false) +{ +} + +ShadowSettings::ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copyop): + Object(ss,copyop), + _baseShadowTextureUnit(ss._baseShadowTextureUnit), + _textureSize(ss._textureSize), + _minimumShadowMapNearFarRatio(ss._minimumShadowMapNearFarRatio), + _shadowMapProjectionHint(ss._shadowMapProjectionHint), + _perspectiveShadowMapCutOffAngle(ss._perspectiveShadowMapCutOffAngle), + _shaderHint(ss._shaderHint), + _debugDraw(ss._debugDraw) +{ +} + +ShadowSettings::~ShadowSettings() +{ +} diff --git a/src/osgShadow/ShadowedScene.cpp b/src/osgShadow/ShadowedScene.cpp index b874030cd..43510e210 100644 --- a/src/osgShadow/ShadowedScene.cpp +++ b/src/osgShadow/ShadowedScene.cpp @@ -23,23 +23,34 @@ using namespace osgShadow; ShadowedScene::ShadowedScene(ShadowTechnique* st): _receivesShadowTraversalMask(0xffffffff), - _castsShadowTraversalMask(0xffffffff) + _castsShadowTraversalMask(0xffffffff) { setNumChildrenRequiringUpdateTraversal(1); - if (st) setShadowTechnique(st); + setShadowSettings(new ShadowSettings); + + if (st) setShadowTechnique(st); } -ShadowedScene::ShadowedScene(const ShadowedScene& copy, const osg::CopyOp& copyop): - osg::Group(copy,copyop), - _receivesShadowTraversalMask(copy._receivesShadowTraversalMask), - _castsShadowTraversalMask(copy._castsShadowTraversalMask) +ShadowedScene::ShadowedScene(const ShadowedScene& ss, const osg::CopyOp& copyop): + osg::Group(ss,copyop), + _receivesShadowTraversalMask(ss._receivesShadowTraversalMask), + _castsShadowTraversalMask(ss._castsShadowTraversalMask) { setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1); - if (copy._shadowTechnique.valid()) + if (ss._shadowTechnique.valid()) { - setShadowTechnique( dynamic_cast(copy._shadowTechnique->clone(copyop)) ); + setShadowTechnique( dynamic_cast(ss._shadowTechnique->clone(copyop)) ); + } + + if (ss._shadowSettings) + { + setShadowSettings(ss._shadowSettings.get()); + } + else + { + setShadowSettings(new ShadowSettings); } } @@ -61,6 +72,11 @@ void ShadowedScene::traverse(osg::NodeVisitor& nv) } } +void ShadowedScene::setShadowSettings(ShadowSettings* ss) +{ + _shadowSettings = ss; +} + void ShadowedScene::setShadowTechnique(ShadowTechnique* technique) { if (_shadowTechnique == technique) return; diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index be8f5123f..201a26c34 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2011 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -285,7 +285,10 @@ ViewDependentShadowMap::ShadowData::ShadowData(ViewDependentShadowMap::ViewDepen _viewDependentData(vdd), _textureUnit(0) { - bool debug = vdd->getViewDependentShadowMap()->getDebugDraw(); + + const ShadowSettings* settings = vdd->getViewDependentShadowMap()->getShadowedScene()->getShadowSettings(); + + bool debug = settings->getDebugDraw(); // set up texgen _texgen = new osg::TexGen; @@ -293,7 +296,7 @@ ViewDependentShadowMap::ShadowData::ShadowData(ViewDependentShadowMap::ViewDepen // set up the texture _texture = new osg::Texture2D; - osg::Vec2s textureSize = debug ? osg::Vec2s(512,512) : vdd->getViewDependentShadowMap()->getTextureSize(); + osg::Vec2s textureSize = debug ? osg::Vec2s(512,512) : settings->getTextureSize(); _texture->setTextureSize(textureSize.x(), textureSize.y()); if (debug) @@ -522,28 +525,13 @@ void ViewDependentShadowMap::ViewDependentData::releaseGLObjects(osg::State* sta // ViewDependentShadowMap // ViewDependentShadowMap::ViewDependentShadowMap(): - ShadowTechnique(), - _baseShadowTextureUnit(1), - _textureSize(2048,2048), - _minimumShadowMapNearFarRatio(0.01), - _shadowMapProjectionHint(PERSPECTIVE_SHADOW_MAP), - _perspectiveShadowMapCutOffAngle(2.0), - _shaderHint(NO_SHADERS), -// _shaderHint(PROVIDE_FRAGMENT_SHADER), - _debugDraw(false) + ShadowTechnique() { _shadowRecievingPlaceholderStateSet = new osg::StateSet; } ViewDependentShadowMap::ViewDependentShadowMap(const ViewDependentShadowMap& vdsm, const osg::CopyOp& copyop): - ShadowTechnique(vdsm,copyop), - _baseShadowTextureUnit(vdsm._baseShadowTextureUnit), - _textureSize(vdsm._textureSize), - _minimumShadowMapNearFarRatio(vdsm._minimumShadowMapNearFarRatio), - _shadowMapProjectionHint(vdsm._shadowMapProjectionHint), - _perspectiveShadowMapCutOffAngle(vdsm._perspectiveShadowMapCutOffAngle), - _shaderHint(vdsm._shaderHint), - _debugDraw(vdsm._debugDraw) + ShadowTechnique(vdsm,copyop) { _shadowRecievingPlaceholderStateSet = new osg::StateSet; } @@ -662,8 +650,10 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv) // create a list of light sources + their matrices to place them selectActiveLights(&cv, vdd); + ShadowSettings* settings = getShadowedScene()->getShadowSettings(); + unsigned int pos_x = 0; - unsigned int textureUnit = _baseShadowTextureUnit; + unsigned int textureUnit = settings->getBaseShadowTextureUnit(); unsigned int numValidShadows = 0; ShadowDataList& sdl = vdd->getShadowDataList(); @@ -698,7 +688,7 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv) osg::ref_ptr camera = sd->_camera; - if (_debugDraw) + if (settings->getDebugDraw()) { camera->getViewport()->x() = pos_x; pos_x += camera->getViewport()->width() + 40; @@ -744,7 +734,7 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv) cv.popStateSet(); - if (!orthographicViewFrustum && _shadowMapProjectionHint==PERSPECTIVE_SHADOW_MAP) + if (!orthographicViewFrustum && settings->getShadowMapProjectionHint()==ShadowSettings::PERSPECTIVE_SHADOW_MAP) { adjustPerspectiveShadowMapCameraSettings(vdsmCallback->getRenderStage(), frustum, pl, camera.get()); if (vdsmCallback->getProjectionMatrix()) @@ -838,7 +828,9 @@ void ViewDependentShadowMap::createShaders() _shadowCastingStateSet = new osg::StateSet; - if (!_debugDraw) + ShadowSettings* settings = getShadowedScene()->getShadowSettings(); + + if (!settings->getDebugDraw()) { // note soft (attribute only no mode override) setting. When this works ? // 1. for objects prepared for backface culling @@ -876,21 +868,21 @@ void ViewDependentShadowMap::createShaders() osg::ref_ptr baseTextureUnit = new osg::Uniform("baseTextureUnit",(int)_baseTextureUnit); _uniforms.push_back(baseTextureUnit.get()); - osg::ref_ptr shadowTextureSampler = new osg::Uniform("shadowTexture",(int)_baseShadowTextureUnit); + osg::ref_ptr shadowTextureSampler = new osg::Uniform("shadowTexture",(int)(settings->getBaseShadowTextureUnit())); _uniforms.push_back(shadowTextureSampler.get()); - osg::ref_ptr shadowTextureUnit = new osg::Uniform("shadowTextureUnit",(int)_baseShadowTextureUnit); + osg::ref_ptr shadowTextureUnit = new osg::Uniform("shadowTextureUnit",(int)(settings->getBaseShadowTextureUnit())); _uniforms.push_back(shadowTextureUnit.get()); - switch(_shaderHint) + switch(settings->getShaderHint()) { - case(NO_SHADERS): + case(ShadowSettings::NO_SHADERS): { OSG_NOTICE<<"No shaders provided by, user must supply own shaders"< fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource_noBaseTexture); osg::ref_ptr fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource_withBaseTexture); @@ -1045,9 +1037,11 @@ bool ViewDependentShadowMap::computeShadowCameraSettings(Frustum& frustum, Light osg::Vec3d lightSide; + const ShadowSettings* settings = getShadowedScene()->getShadowSettings(); + double dotProduct_v = positionedLight.lightDir * frustum.frustumCenterLine; double gamma_v = acos(dotProduct_v); - if (gamma_vosg::DegreesToRadians(180.0-_perspectiveShadowMapCutOffAngle)) + if (gamma_vgetPerspectiveShadowMapCutOffAngle()) || gamma_v>osg::DegreesToRadians(180.0-settings->getPerspectiveShadowMapCutOffAngle())) { OSG_INFO<<"View direction and Light direction below tolerance"<getShadowSettings(); //frustum.projectionMatrix; //frustum.modelViewMatrix; @@ -1608,7 +1603,7 @@ bool ViewDependentShadowMap::adjustPerspectiveShadowMapCameraSettings(osgUtil::R double dotProduct_v = lightdir * viewdir_v; double gamma_v = acos(dotProduct_v); - if (gamma_vosg::DegreesToRadians(180-_perspectiveShadowMapCutOffAngle)) + if (gamma_vgetPerspectiveShadowMapCutOffAngle()) || gamma_v>osg::DegreesToRadians(180-settings->getPerspectiveShadowMapCutOffAngle())) { // OSG_NOTICE<<"Light and view vectors near parrallel - use standard shadow map."<getMinimumShadowMapNearFarRatio()); if (n