diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index ca1fc7eb8..4d8edec42 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -56,18 +56,6 @@ namespace SceneUtil } state.applyModelViewMatrix(modelViewMatrix); - - /* - for (int i=0; i<8; ++i) - { - osg::ref_ptr defaultLight (new osg::Light(i)); - defaultLight->setAmbient(osg::Vec4()); - defaultLight->setDiffuse(osg::Vec4()); - defaultLight->setSpecular(osg::Vec4()); - defaultLight->setConstantAttenuation(0.f); - state.setGlobalDefaultAttribute(defaultLight); - } - */ } private: @@ -204,18 +192,18 @@ namespace SceneUtil return found->second; else { + osg::ref_ptr stateset = new osg::StateSet; - std::vector > lights; for (unsigned int i=0; i > lights; lights.push_back(lightList[i]->mLightSource->getLight(frameNum)); + osg::ref_ptr attr = new LightStateAttribute(mStartLight+i, lights); + // don't use setAttributeAndModes, that does not support light indices! + stateset->setAttribute(attr, osg::StateAttribute::ON); + stateset->setAssociatedModes(attr, osg::StateAttribute::ON); - osg::ref_ptr attr = new LightStateAttribute(mStartLight, lights); - - osg::ref_ptr stateset = new osg::StateSet; - - // don't use setAttributeAndModes, that does not support light indices! - stateset->setAttribute(attr, osg::StateAttribute::ON); - stateset->setAssociatedModes(attr, osg::StateAttribute::ON); + } stateSetCache.insert(std::make_pair(hash, stateset)); return stateset; @@ -254,6 +242,17 @@ namespace SceneUtil void LightManager::setStartLight(int start) { mStartLight = start; + + // Set default light state to zero + for (int i=start; i<8; ++i) + { + osg::ref_ptr defaultLight (new osg::Light(i)); + defaultLight->setAmbient(osg::Vec4()); + defaultLight->setDiffuse(osg::Vec4()); + defaultLight->setSpecular(osg::Vec4()); + defaultLight->setConstantAttenuation(0.f); + getOrCreateStateSet()->setAttributeAndModes(defaultLight, osg::StateAttribute::OFF); + } } int LightManager::getStartLight() const