Discard culled lights specifically for post-processing light buffer

esm4-texture
Alexei Kotov 7 months ago
parent 05815b3952
commit 71c1b536b4

@ -1122,8 +1122,10 @@ namespace SceneUtil
} }
const std::vector<LightManager::LightSourceViewBound>& LightManager::getLightsInViewSpace( const std::vector<LightManager::LightSourceViewBound>& LightManager::getLightsInViewSpace(
osg::Camera* camera, const osg::RefMatrix* viewMatrix, size_t frameNum) osgUtil::CullVisitor* cv, const osg::RefMatrix* viewMatrix, size_t frameNum)
{ {
osg::Camera* camera = cv->getCurrentCamera();
osg::observer_ptr<osg::Camera> camPtr(camera); osg::observer_ptr<osg::Camera> camPtr(camera);
auto it = mLightsInViewSpace.find(camPtr); auto it = mLightsInViewSpace.find(camPtr);
@ -1175,13 +1177,22 @@ namespace SceneUtil
if (fillPPLights) if (fillPPLights)
{ {
osg::CullingSet& cullingSet = cv->getModelViewCullingStack().front();
for (const auto& bound : it->second) for (const auto& bound : it->second)
{ {
if (bound.mLightSource->getEmpty()) if (bound.mLightSource->getEmpty())
continue; continue;
const auto* light = bound.mLightSource->getLight(frameNum); const auto* light = bound.mLightSource->getLight(frameNum);
if (light->getDiffuse().x() >= 0.f) // Ignore negative lights
mPPLightBuffer->setLight(frameNum, light, bound.mLightSource->getRadius()); if (light->getDiffuse().x() < 0.f)
continue;
const float radius = bound.mLightSource->getRadius();
osg::BoundingSphere frustumBound = bound.mViewBound;
frustumBound.radius() = radius * 2.f;
// Ignore culled lights
if (cullingSet.isCulled(frustumBound))
continue;
mPPLightBuffer->setLight(frameNum, light, radius);
} }
} }
@ -1291,7 +1302,7 @@ namespace SceneUtil
transformBoundingSphere(*cv->getModelViewMatrix(), nodeBound); transformBoundingSphere(*cv->getModelViewMatrix(), nodeBound);
const std::vector<LightManager::LightSourceViewBound>& lights const std::vector<LightManager::LightSourceViewBound>& lights
= mLightManager->getLightsInViewSpace(cv->getCurrentCamera(), viewMatrix, mLastFrameNumber); = mLightManager->getLightsInViewSpace(cv, viewMatrix, mLastFrameNumber);
mLightList.clear(); mLightList.clear();
for (const LightManager::LightSourceViewBound& light : lights) for (const LightManager::LightSourceViewBound& light : lights)

@ -238,7 +238,7 @@ namespace SceneUtil
void addLight(LightSource* lightSource, const osg::Matrixf& worldMat, size_t frameNum); void addLight(LightSource* lightSource, const osg::Matrixf& worldMat, size_t frameNum);
const std::vector<LightSourceViewBound>& getLightsInViewSpace( const std::vector<LightSourceViewBound>& getLightsInViewSpace(
osg::Camera* camera, const osg::RefMatrix* viewMatrix, size_t frameNum); osgUtil::CullVisitor* cv, const osg::RefMatrix* viewMatrix, size_t frameNum);
osg::ref_ptr<osg::StateSet> getLightListStateSet( osg::ref_ptr<osg::StateSet> getLightListStateSet(
const LightList& lightList, size_t frameNum, const osg::RefMatrix* viewMatrix); const LightList& lightList, size_t frameNum, const osg::RefMatrix* viewMatrix);

Loading…
Cancel
Save