diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 65955d9afc..713524a418 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -274,59 +274,44 @@ namespace SceneUtil if (lights.size()) { + // we do the intersections in view space + osg::BoundingSphere nodeBound = node->getBound(); + osg::Matrixf mat = *cv->getModelViewMatrix(); + transformBoundingSphere(mat, nodeBound); - static std::map > statesets; - std::map >::iterator found = statesets.find(node); - osg::ref_ptr stateset; - if (found != statesets.end()) + std::vector lightList; + for (unsigned int i=0; isecond; - } - else{ - - // we do the intersections in view space - osg::BoundingSphere nodeBound = node->getBound(); - osg::Matrixf mat = *cv->getModelViewMatrix(); - transformBoundingSphere(mat, nodeBound); - - std::vector lightList; - for (unsigned int i=0; i (8 - mLightManager->getStartLight()); - - if (lightList.size() > maxLights) - { - //std::cerr << "More than 8 lights!" << std::endl; - - // TODO: sort lights by certain criteria - - while (lightList.size() > maxLights) - lightList.pop_back(); - } - - stateset = mLightManager->getLightListStateSet(lightList); - statesets[node] = stateset; + const LightManager::LightSourceTransform& l = lights[i]; + if (l.mViewBound.intersects(nodeBound)) + lightList.push_back(l.mLightSource); } - if (stateset) - cv->pushStateSet(stateset); + if (lightList.empty()) + { + traverse(node, nv); + return; + } + + unsigned int maxLights = static_cast (8 - mLightManager->getStartLight()); + + if (lightList.size() > maxLights) + { + //std::cerr << "More than 8 lights!" << std::endl; + + // TODO: sort lights by certain criteria + + while (lightList.size() > maxLights) + lightList.pop_back(); + } + + osg::StateSet* stateset = mLightManager->getLightListStateSet(lightList); + + cv->pushStateSet(stateset); traverse(node, nv); - if (stateset) - cv->popStateSet(); + cv->popStateSet(); } else traverse(node, nv);