Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of shadow casting lights in ogre2 #155

Merged
merged 2 commits into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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