fix distinct directional lights per view #19147
Open
+105
−64
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.
Objective
after #15156 it seems like using distinct directional lights on different views is broken (and will probably break spotlights too). fix them
Solution
the reason is a bit hairy so with an example:
in render/lights.rs:
outside of any view loop,
depth_texture_base_index
for each (0-1 for one light, 2-3 for the other, depending on iteration order) (line 1034)in the view loop, for directional lights we
then in the rendergraph:
camera 0 renders the shadow map for light 0 to texture indices 0 and 1
camera 0 renders using shadows from the
depth_texture_base_index
(maybe 0-1, maybe 2-3 depending on the iteration order)camera 1 renders the shadow map for light 1 to texture indices 0 and 1
camera 0 renders using shadows from the
depth_texture_base_index
(maybe 0-1, maybe 2-3 depending on the iteration order)issues:
shadows_enabled: false
(just inefficient)solution:
nice side effects:
max_texture_array_layers / MAX_CASCADES_PER_LIGHT
shadow-casting directional lights per view, rather than overall.GpuDirectionalLight::skip
field, since the gpu lights struct is constructed per viewa simpler approach would be to keep everything the same, and just increment the texture layer index in the view loop even for non-intersecting lights. this pr reduces the total shadowmap vram used as well and isn't much extra complexity. but if we want something less risky/intrusive for 16.1 that would be the way.
Testing
i edited the split screen example to put separate lights on layer 1 and layer 2, and put the plane and fox on both layers (using lots of unrelated code for render layer propagation from #17575).
without the fix the directional shadows will only render on one of the top 2 views even though there are directional lights on both layers.