forked from teamnwah/openmw-tes3coop
Cache the light list in LightListCallback
When multiple cameras are rendering, the later cameras can reuse the light lists from the first camera.
This commit is contained in:
parent
1cf1c944b7
commit
c23609e22b
2 changed files with 25 additions and 16 deletions
|
@ -280,37 +280,40 @@ namespace SceneUtil
|
|||
// - cull list of lights by the camera frustum
|
||||
// - organize lights in a quad tree
|
||||
|
||||
// Don't use Camera::getViewMatrix, that one might be relative to another camera!
|
||||
const osg::RefMatrix* viewMatrix = cv->getCurrentRenderStage()->getInitialViewMatrix();
|
||||
|
||||
const std::vector<LightManager::LightSourceViewBound>& lights = mLightManager->getLightsInViewSpace(cv->getCurrentCamera(), viewMatrix);
|
||||
|
||||
if (lights.size())
|
||||
// update light list if necessary
|
||||
// makes sure we don't update it more than once per frame when rendering with multiple cameras
|
||||
if (mLastFrameNumber != nv->getFrameStamp()->getFrameNumber())
|
||||
{
|
||||
mLastFrameNumber = nv->getFrameStamp()->getFrameNumber();
|
||||
|
||||
// Don't use Camera::getViewMatrix, that one might be relative to another camera!
|
||||
const osg::RefMatrix* viewMatrix = cv->getCurrentRenderStage()->getInitialViewMatrix();
|
||||
const std::vector<LightManager::LightSourceViewBound>& lights = mLightManager->getLightsInViewSpace(cv->getCurrentCamera(), viewMatrix);
|
||||
|
||||
// we do the intersections in view space
|
||||
osg::BoundingSphere nodeBound = node->getBound();
|
||||
osg::Matrixf mat = *cv->getModelViewMatrix();
|
||||
transformBoundingSphere(mat, nodeBound);
|
||||
|
||||
LightManager::LightList lightList;
|
||||
mLightList.clear();
|
||||
for (unsigned int i=0; i<lights.size(); ++i)
|
||||
{
|
||||
const LightManager::LightSourceViewBound& l = lights[i];
|
||||
if (l.mViewBound.intersects(nodeBound))
|
||||
lightList.push_back(&l);
|
||||
mLightList.push_back(&l);
|
||||
}
|
||||
|
||||
if (lightList.empty())
|
||||
{
|
||||
traverse(node, nv);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (mLightList.size())
|
||||
{
|
||||
unsigned int maxLights = static_cast<unsigned int> (8 - mLightManager->getStartLight());
|
||||
|
||||
if (lightList.size() > maxLights)
|
||||
osg::StateSet* stateset = NULL;
|
||||
|
||||
if (mLightList.size() > maxLights)
|
||||
{
|
||||
// remove lights culled by this camera
|
||||
LightManager::LightList lightList = mLightList;
|
||||
for (LightManager::LightList::iterator it = lightList.begin(); it != lightList.end() && lightList.size() > maxLights; )
|
||||
{
|
||||
osg::CullStack::CullingStack& stack = cv->getModelViewCullingStack();
|
||||
|
@ -334,9 +337,11 @@ namespace SceneUtil
|
|||
while (lightList.size() > maxLights)
|
||||
lightList.pop_back();
|
||||
}
|
||||
stateset = mLightManager->getLightListStateSet(lightList);
|
||||
}
|
||||
else
|
||||
stateset = mLightManager->getLightListStateSet(mLightList);
|
||||
|
||||
osg::StateSet* stateset = mLightManager->getLightListStateSet(lightList);
|
||||
|
||||
cv->pushStateSet(stateset);
|
||||
|
||||
|
|
|
@ -113,11 +113,13 @@ namespace SceneUtil
|
|||
int mStartLight;
|
||||
};
|
||||
|
||||
/// @note Not thread safe for CullThreadPerCamera threading mode.
|
||||
class LightListCallback : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
LightListCallback()
|
||||
: mLightManager(NULL)
|
||||
, mLastFrameNumber(0)
|
||||
{}
|
||||
LightListCallback(const LightListCallback& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY)
|
||||
: osg::Object(copy, copyop), osg::NodeCallback(copy, copyop), mLightManager(copy.mLightManager)
|
||||
|
@ -129,6 +131,8 @@ namespace SceneUtil
|
|||
|
||||
private:
|
||||
LightManager* mLightManager;
|
||||
unsigned int mLastFrameNumber;
|
||||
LightManager::LightList mLightList;
|
||||
};
|
||||
|
||||
/// @brief Configures a light's attenuation according to vanilla Morrowind attenuation settings.
|
||||
|
|
Loading…
Reference in a new issue