Skip to content

Commit

Permalink
Merge branch 'visiblepp' into 'master'
Browse files Browse the repository at this point in the history
Discard culled lights specifically for post-processing light buffer (#8009)

Closes #8009

See merge request OpenMW/openmw!4144
  • Loading branch information
psi29a committed Jun 4, 2024
2 parents c7f3277 + 71c1b53 commit 2369694
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions components/sceneutil/lightmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,10 @@ namespace SceneUtil
}

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);
auto it = mLightsInViewSpace.find(camPtr);

Expand Down Expand Up @@ -1175,13 +1177,22 @@ namespace SceneUtil

if (fillPPLights)
{
osg::CullingSet& cullingSet = cv->getModelViewCullingStack().front();
for (const auto& bound : it->second)
{
if (bound.mLightSource->getEmpty())
continue;
const auto* light = bound.mLightSource->getLight(frameNum);
if (light->getDiffuse().x() >= 0.f)
mPPLightBuffer->setLight(frameNum, light, bound.mLightSource->getRadius());
// Ignore negative lights
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);
}
}

Expand Down Expand Up @@ -1291,7 +1302,7 @@ namespace SceneUtil
transformBoundingSphere(*cv->getModelViewMatrix(), nodeBound);

const std::vector<LightManager::LightSourceViewBound>& lights
= mLightManager->getLightsInViewSpace(cv->getCurrentCamera(), viewMatrix, mLastFrameNumber);
= mLightManager->getLightsInViewSpace(cv, viewMatrix, mLastFrameNumber);

mLightList.clear();
for (const LightManager::LightSourceViewBound& light : lights)
Expand Down
2 changes: 1 addition & 1 deletion components/sceneutil/lightmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ namespace SceneUtil
void addLight(LightSource* lightSource, const osg::Matrixf& worldMat, size_t frameNum);

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(
const LightList& lightList, size_t frameNum, const osg::RefMatrix* viewMatrix);
Expand Down

0 comments on commit 2369694

Please sign in to comment.