Repository navigation
Skip spot light shadow maps that don't overlap the view frustum - #1788
sunabouzu1991 wants to merge 1 commit into
Conversation
The bounds were empty in this case, which gave the shadow map a degenerate projection with a frustum that culls nothing and makes every PagedLOD request its high resolution child. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I have done a first pass review and this doesn't look like an efficient way to resolve the problem at all. Far better is to cull the light source before it ever gets processed by ViewDependentState. I will review the RecordTraversal::apply(SpotLight& ) and apply(PointLight&) code with a view to adding culling against the view frustum and maxShadowDistance. |
|
I have merged your changes to vsgspotshadow and try this out as a test case. |
|
Thanks, culling the light before ViewDependentState makes sense, I'm happy to close this in favour of that. One thing to watch: a spot light beyond maxShadowDistance can still light visible surfaces, so I think that distance should only drop its shadow map, while the light itself is culled against the view frustum. The clipped bounds can also be finite but inverted (min > max), not only the initial empty box. I can test your change with my scene when it's ready. |
|
I think we'll need to 2 cull tests - one potentially in the RecordTraversal that culls the light against the frustum to see if that light should be entered into the lightData passed to GPU for lighting, and another within ViewDependentState against the shadow extents to see if that light might affect the shadows. Potentially both could be done within the ViewDependentState. I will ponder on this today. |
|
To help with testing I have merged this PR as branch: https://github.com/vsg-dev/VulkanSceneGraph/tree/sunabouzu1991-empty-spot-shadow-bounds |
|
I have invested the issue that this PR attempts to solve and found that the problem goes far earlier in the sequence of operations that are down for both PointLight and SpotLight. So I'll close this PR as it's replaced by the more complete fix in #1790. The fix I went for was to changed RecordTraversal to cull PointLight and SpotLight based on the radius of the influence that their illumination will cover, and to change ViewDepenedentState::traverse(..) so that shadow map culling is done and if any shadow maps are culled the number of shadow maps is adjusted. This approach reduces the number of lights that are occupying the lightData passed to the GPU and the number of shadow map slots that are used. This will help performance and visual quality in complex scenes. |
Description
For a spot light with shadows,
ViewDependentState::traverse()fits the shadow map to the part of the view frustum (up tomaxShadowDistance) that is inside the light's frustum. When they don't overlap the bounds end up with min > max, which isn't checked. If the bounds are empty the scale intweakedOrthographicis 2 / -inf, so the shadow map is rendered with a degenerate projection:State::lodDistance()is 1.414 for every sphere that passes, so everyPagedLODrequests its high resolution childI came across this with a paged 16km x 16km terrain, a small spot light and the camera 2.7km away from it. The
DatabasePagerwent on loading tiles for as long as I left it running (12314 activePagedLODafter 70 seconds, and around 80 without the light).This PR doesn't render the shadow map in this case. The light data keeps its layout, the matrix maps all positions to outside the shadow map.
How Has This Been Tested?
I added a
--pagedtest case tovsgspotshadow: https://github.com/sunabouzu1991/vsgExamples/tree/spot-shadow-paged. It has 1024PagedLODtiles and counts how many of them are read in high resolution, with a spot light 500m from the camera andmaxShadowDistanceof 60m.vsgspotshadow --pagedvsgspotshadow --paged --no-shadowsWith the original
vsgspotshadowscene (maxShadowDistanceof 60m) the light data is the same before and after. Adding two more shadowed spot lights that are out of range in front of the visible one doesn't change the image. No validation errors.Linux, GTX 1650, hard shadows.
🤖 Generated with Claude Code