Opt-in-Per-Camera Pointlight and Spotlight Shadow Maps#24625
Open
kfc35 wants to merge 30 commits into
Open
Conversation
Contributor
Author
|
Hm there appears to an issue with rendering when there are multiple PointLights since my index math is messed up on the shader code side. Will figure it out |
3d1be2a to
ad3d74b
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This is intended to be that follow-up if I understood the intention correctly 😅
This idea has also floated around on Discord, with an emphasis on this being configurable, so I preserved that desire in this PR.
Solution
A new property,
has_own_shadow_maps, has been added toCamera. By default, this is set tofalse, preserving existing behavior.If a camera requests its own shadow maps, new depth attachments and
ShadowViews are created for these additional views inprepare_lightsinlight.rs, which is where the meat of this PR is.prepare_lightsalso manages what happens if the light itself changes or the views that opt in change. There’s also an added optimization that if all the cameras request their own shadow maps, the view-agnostic pointlight/spotlight shadow map is removed/not created.The shader code changes are to ensure the new shadow maps are actually being used. Two new indices offset,
point_spot_shadow_map_index_mult_offsetand…_add_offset, are used to correctly index into the correct shadow maps. A lot of the wgsl code changes are to refactor a variable fromlight_idtoarray_index, as this more accurately describes its use and it matches the corresponding shadow sampling code for spotlight shadows. (actively soliciting for less verbose names 😆 )Testing
For correctness:
cargo run --example testbed_3d --features=“area_light_luts” -- renderlayersI tested with the render_layers (with the changes I put in for the light to be on the 3 render layers). It works as expected now!
I tested both a
PointLightand aSpotLight(have to change the Spotlight transform to add a looking_at:Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::new(3.0, 0.5, 0.0), Vec3::Y)))I’ll probably run the bevy example runner against this PR to ensure there are no correctness regressions otherwise.
I have not done any performance testing (nor know if it’s necesssary). I don’t know if there is a performance regression in the regular “no camera has their own shadow map” case or if we should be concerned about that. If someone can help with this, I’d be indebted.
Showcase
The render layers scene in the 3d testbed with a PointLight now after the changes in this PR:

The same scene with a SpotLight instead described above in Testing:
