diff --git a/include/osgShadow/ShadowSettings b/include/osgShadow/ShadowSettings index db9354147..12f86d504 100644 --- a/include/osgShadow/ShadowSettings +++ b/include/osgShadow/ShadowSettings @@ -28,8 +28,11 @@ class OSGSHADOW_EXPORT ShadowSettings : public osg::Object META_Object(osgShadow, ShadowSettings); - void setLightNum(unsigned int lightNum) { _lightNum = lightNum; } - unsigned int getLightNum() const { return _lightNum; } + /** Set the LightNum of the light in the scene to assign a shadow for. + * Default value is -1, which signifies that shadow technique should automatically select an active light + * to assign a shadow, typically this will be the first active light found. */ + void setLightNum(int lightNum) { _lightNum = lightNum; } + int getLightNum() const { return _lightNum; } void setBaseShadowTextureUnit(unsigned int unit) { _baseShadowTextureUnit = unit; } unsigned int getBaseShadowTextureUnit() const { return _baseShadowTextureUnit; } @@ -79,7 +82,7 @@ class OSGSHADOW_EXPORT ShadowSettings : public osg::Object virtual ~ShadowSettings(); - unsigned int _lightNum; + int _lightNum; unsigned int _baseShadowTextureUnit; osg::Vec2s _textureSize; diff --git a/src/osgShadow/ShadowSettings.cpp b/src/osgShadow/ShadowSettings.cpp index e8ecdcf70..25c5e19e7 100644 --- a/src/osgShadow/ShadowSettings.cpp +++ b/src/osgShadow/ShadowSettings.cpp @@ -16,6 +16,7 @@ using namespace osgShadow; ShadowSettings::ShadowSettings(): + _lightNum(-1), _baseShadowTextureUnit(1), _textureSize(2048,2048), _minimumShadowMapNearFarRatio(0.01), @@ -29,6 +30,7 @@ ShadowSettings::ShadowSettings(): ShadowSettings::ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copyop): Object(ss,copyop), + _lightNum(ss._lightNum), _baseShadowTextureUnit(ss._baseShadowTextureUnit), _textureSize(ss._textureSize), _minimumShadowMapNearFarRatio(ss._minimumShadowMapNearFarRatio), diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index 5ce83e9c8..352075fb9 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -790,6 +790,9 @@ bool ViewDependentShadowMap::selectActiveLights(osgUtil::CullVisitor* cv, ViewDe osgUtil::PositionalStateContainer::AttrMatrixList& aml = rs->getPositionalStateContainer()->getAttrMatrixList(); + + const ShadowSettings* settings = getShadowedScene()->getShadowSettings(); + for(osgUtil::PositionalStateContainer::AttrMatrixList::reverse_iterator itr = aml.rbegin(); itr != aml.rend(); ++itr) @@ -797,6 +800,9 @@ bool ViewDependentShadowMap::selectActiveLights(osgUtil::CullVisitor* cv, ViewDe const osg::Light* light = dynamic_cast(itr->first.get()); if (light) { + // is LightNum matched to that defined in settings + if (settings && settings->getLightNum()>=0 && light->getLightNum()!=settings->getLightNum()) break; + LightDataList::iterator pll_itr = pll.begin(); for(; pll_itr != pll.end(); ++pll_itr) {