[WIP] Tighter shadow caster culling #33340
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Existing shadow caster culling using the octree only is very approximate. This PR adds the highly encapsulated class VisualServerLightCuller explicitly to deal with the problem, it is very easy and requires minimal change to use with the existing system and will also work with vulkan branch.
The tests done are very cheap and are unlikely to have any measurable detrimental effect even in extreme circumstances. In game levels using realtime lights the culling will typically offer a modest improvement to FPS, typically around 10%, although frame rate can more than double in some circumstances (directional lights like a sun particularly with PSSM can offer a large improvement).
There is functionality for spotlights, omni and directional.
Notes
You can see how it works in this video (ignore the rooms and portals, that is a separate system):
https://www.youtube.com/watch?v=1WT5AXZlsDc
The blue lines from the light sources to the camera frustum show the extra culling planes.
References:
http://lspiroengine.com/?p=153
http://www.terathon.com/gdc06_lengyel.pdf
Note that LSpiro's article deals purely with directional lights, and both these articles rely on dot product - I am dealing with point lights (omni, spotlight) by using a distance to plane function to determine back facing frustum planes rather than dot product. I think this is a better approach than that suggested in the Lengyel article.
The most difficult cases for point lights are where the point is close to the camera frustum (possibility of concave silhouette which would not cull correctly). When the light source is inside the frustum I use a different approach and simply cull the shadow casters to the camera frustum, as any caster outside cannot by definition cast shadows back inside.