From acf9fc2d370ef2b782937295def48c17a685ba8e Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 15 Jun 2015 18:15:26 +0200 Subject: [PATCH] Enable per-frame light list updates (Bug #2638, Bug #2654) The performance impact isn't so big anymore since the last commit. --- components/sceneutil/lightmanager.cpp | 77 +++++++++++---------------- 1 file changed, 31 insertions(+), 46 deletions(-) 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);