From aad8e7b6d0a832e5aa9f874f65aa85a4dd133de7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 15 Jun 2015 19:37:44 +0200 Subject: [PATCH] Light culling fix --- components/sceneutil/lightmanager.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 444530dbe..bcdb4af88 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -145,6 +145,10 @@ namespace SceneUtil { mLightsInViewSpace = false; mLights.clear(); + + // do an occasional cleanup for orphaned lights + if (mStateSetCache.size() > 5000) + mStateSetCache.clear(); } void LightManager::addLight(LightSource* lightSource, osg::Matrix worldMat) @@ -304,11 +308,14 @@ namespace SceneUtil if (lightList.size() > maxLights) { // remove lights culled by this camera - for (LightManager::LightList::iterator it = lightList.begin(); it != lightList.end();) + for (LightManager::LightList::iterator it = lightList.begin(); it != lightList.end() && lightList.size() > maxLights; ) { - osg::CullStack::CullingStack& stack = cv->getProjectionCullingStack(); + osg::CullStack::CullingStack& stack = cv->getModelViewCullingStack(); - if (stack.back().isCulled(osg::BoundingSphere((*it)->mViewBound.center(), (*it)->mViewBound.radius()*2))) + osg::BoundingSphere bs = (*it)->mViewBound; + bs._radius = bs._radius*2; + osg::CullingSet& cullingSet = stack.front(); + if (cullingSet.isCulled(bs)) { it = lightList.erase(it); continue;