Skip to content

Commit

Permalink
Limit number of shadow casting lights in ogre2 (#155)
Browse files Browse the repository at this point in the history
* limit num of shadow casting lights

Signed-off-by: Ian Chen <[email protected]>

* add warning about limit

Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Oct 5, 2020
1 parent 8f049ce commit 7253594
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ogre2/src/Ogre2RenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ void Ogre2RenderTarget::UpdateShadowNode()
}
}

// limit number of shadow maps
// shaders dynamically generated by ogre produce compile error at runtime if
// the number of shadow maps exceeds certain number. The error seems to
// suggest that the number of uniform variables has exceeded the max number
// allowed
unsigned int maxShadowMaps = 25u;
if (dirLightCount * 3 + spotPointLightCount > maxShadowMaps)
{
dirLightCount = std::min(static_cast<unsigned int>(maxShadowMaps / 3),
dirLightCount);
spotPointLightCount = std::min(
std::max(maxShadowMaps - dirLightCount * 3, 0u), spotPointLightCount);
ignwarn << "Number of shadow-casting lights exceeds the limit supported by "
<< "the underlying rendering engine ogre2. Limiting to "
<< dirLightCount << " directional lights and "
<< spotPointLightCount << " point / spot lights" << std::endl;
}

auto engine = Ogre2RenderEngine::Instance();
Ogre::CompositorManager2 *compositorManager =
engine->OgreRoot()->getCompositorManager2();
Expand Down Expand Up @@ -386,6 +404,7 @@ void Ogre2RenderTarget::UpdateShadowNode()
unsigned int colIdx = 0;
unsigned int rowSize = maxTexSize / texSize;
unsigned int colSize = rowSize;

for (unsigned int i = 0; i < spotPointLightCount; ++i)
{
shadowParam.technique = Ogre::SHADOWMAP_FOCUSED;
Expand Down

0 comments on commit 7253594

Please sign in to comment.