mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-19 10:09:43 +00:00
pass sorted lights to light postprocess light buffers
This commit is contained in:
parent
33c66e3d5e
commit
327b8ecdcb
2 changed files with 22 additions and 24 deletions
|
@ -1140,32 +1140,30 @@ namespace SceneUtil
|
||||||
l.mLightSource = transform.mLightSource;
|
l.mLightSource = transform.mLightSource;
|
||||||
l.mViewBound = viewBound;
|
l.mViewBound = viewBound;
|
||||||
it->second.push_back(l);
|
it->second.push_back(l);
|
||||||
|
|
||||||
if (mPPLightBuffer && it->first->getName() == Constants::SceneCamera)
|
|
||||||
{
|
|
||||||
const auto* light = l.mLightSource->getLight(frameNum);
|
|
||||||
if (light->getDiffuse().x() >= 0.f)
|
|
||||||
{
|
|
||||||
mPPLightBuffer->setLight(frameNum, light->getPosition(),
|
|
||||||
light->getDiffuse(),
|
|
||||||
light->getConstantAttenuation(),
|
|
||||||
light->getLinearAttenuation(),
|
|
||||||
light->getQuadraticAttenuation(),
|
|
||||||
l.mLightSource->getRadius());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (getLightingMethod() == LightingMethod::SingleUBO)
|
const bool fillPPLights = mPPLightBuffer && it->first->getName() == Constants::SceneCamera;
|
||||||
{
|
|
||||||
if (it->second.size() > static_cast<size_t>(getMaxLightsInScene() - 1))
|
if (fillPPLights || getLightingMethod() == LightingMethod::SingleUBO)
|
||||||
{
|
{
|
||||||
auto sorter = [] (const LightSourceViewBound& left, const LightSourceViewBound& right) {
|
auto sorter = [] (const LightSourceViewBound& left, const LightSourceViewBound& right) {
|
||||||
return left.mViewBound.center().length2() - left.mViewBound.radius2() < right.mViewBound.center().length2() - right.mViewBound.radius2();
|
return left.mViewBound.center().length2() - left.mViewBound.radius2() < right.mViewBound.center().length2() - right.mViewBound.radius2();
|
||||||
};
|
};
|
||||||
std::sort(it->second.begin() + 1, it->second.end(), sorter);
|
|
||||||
it->second.erase((it->second.begin() + 1) + (getMaxLightsInScene() - 2), it->second.end());
|
std::sort(it->second.begin(), it->second.end(), sorter);
|
||||||
|
|
||||||
|
if (fillPPLights)
|
||||||
|
{
|
||||||
|
for (const auto& bound : it->second)
|
||||||
|
{
|
||||||
|
const auto* light = bound.mLightSource->getLight(frameNum);
|
||||||
|
if (light->getDiffuse().x() >= 0.f)
|
||||||
|
mPPLightBuffer->setLight(frameNum, light, bound.mLightSource->getRadius());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it->second.size() > static_cast<size_t>(getMaxLightsInScene() - 1))
|
||||||
|
it->second.resize(getMaxLightsInScene() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace SceneUtil
|
||||||
mIndex[frame % 2] = 0;
|
mIndex[frame % 2] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLight(size_t frame, const osg::Vec4f& position, osg::Vec4f diffuse, float ac, float al, float aq, float radius)
|
void setLight(size_t frame, const osg::Light* light, float radius)
|
||||||
{
|
{
|
||||||
size_t frameId = frame % 2;
|
size_t frameId = frame % 2;
|
||||||
size_t i = mIndex[frameId];
|
size_t i = mIndex[frameId];
|
||||||
|
@ -70,9 +70,9 @@ namespace SceneUtil
|
||||||
|
|
||||||
i *= 3;
|
i *= 3;
|
||||||
|
|
||||||
mUniformBuffers[frameId]->setElement(i + 0, position);
|
mUniformBuffers[frameId]->setElement(i + 0, light->getPosition());
|
||||||
mUniformBuffers[frameId]->setElement(i + 1, diffuse);
|
mUniformBuffers[frameId]->setElement(i + 1, light->getDiffuse());
|
||||||
mUniformBuffers[frameId]->setElement(i + 2, osg::Vec4f(ac, al, aq, radius));
|
mUniformBuffers[frameId]->setElement(i + 2, osg::Vec4f(light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), radius));
|
||||||
|
|
||||||
mIndex[frameId]++;
|
mIndex[frameId]++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue