bevy/crates
Marco Buono ef23f465ce
Do not re-check visibility or re-render shadow maps for point and spot lights for each view (#15156)
# Objective

_If I understand it correctly_, we were checking mesh visibility, as
well as re-rendering point and spot light shadow maps for each view.
This makes it so that M views and N lights produce M x N complexity.
This PR aims to fix that, as well as introduce a stress test for this
specific scenario.

## Solution

- Keep track of what lights have already had mesh visibility calculated
and do not calculate it again;
- Reuse shadow depth textures and attachments across all views, and only
render shadow maps for the _first_ time a light is encountered on a
view;
- Directional lights remain unaltered, since their shadow map cascades
are view-dependent;
- Add a new `many_cameras_lights` stress test example to verify the
solution

## Showcase

110% speed up on the stress test
83% reduction of memory usage in stress test

### Before (5.35 FPS on stress test)
<img width="1392" alt="Screenshot 2024-09-11 at 12 25 57"
src="https://github.com/user-attachments/assets/136b0785-e9a4-44df-9a22-f99cc465e126">

### After (11.34 FPS on stress test)
<img width="1392" alt="Screenshot 2024-09-11 at 12 24 35"
src="https://github.com/user-attachments/assets/b8dd858f-5e19-467f-8344-2b46ca039630">


## Testing

- Did you test these changes? If so, how? 
- On my game project where I have two cameras, and many shadow casting
lights I managed to get pretty much double the FPS.
  - Also included a stress test, see the comparison above
- Are there any parts that need more testing?
- Yes, I would like help verifying that this fix is indeed correct, and
that we were really re-rendering the shadow maps by mistake and it's
indeed okay to not do that
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
  - Run the `many_cameras_lights` example
- On the `main` branch, cherry pick the commit with the example (`git
cherry-pick --no-commit 1ed4ace01`) and run it
- If relevant, what platforms did you test these changes on, and are
there any important ones you can't test?
  - macOS

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
2024-11-11 18:49:09 +00:00
..
bevy_a11y Remove accesskit re-export from bevy_a11y (#16257) 2024-11-08 21:01:16 +00:00
bevy_animation Fix permissions of rust source files (#16310) 2024-11-09 16:34:38 +00:00
bevy_app Improve SubApp documentation example (#16160) 2024-10-30 22:12:25 +00:00
bevy_asset Support creating asset directories (#16220) 2024-11-04 22:06:00 +00:00
bevy_audio AudioPlayer::new() (#16287) 2024-11-08 01:51:50 +00:00
bevy_color Upgrade to wgpu 23 (#15988) 2024-11-05 21:18:48 +00:00
bevy_core chore(deps): remove unused uuid dependency from bevy_core (#16253) 2024-11-05 23:31:58 +00:00
bevy_core_pipeline Fix missing import (#16337) 2024-11-11 18:48:41 +00:00
bevy_derive move ANDROID_APP to bevy_window (#15585) 2024-10-02 03:01:06 +00:00
bevy_dev_tools fix bevy_dev_tools build (#16099) 2024-10-25 20:14:39 +00:00
bevy_diagnostic Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
bevy_dylib Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_ecs Add EntityMut::get_mut_by_id_unchecked (#16210) 2024-11-11 18:46:47 +00:00
bevy_encase_derive Update `glam to 0.29, encase` to 0.10. (#15249) 2024-09-23 19:44:02 +00:00
bevy_gilrs Use Name component for gamepad (#16233) 2024-11-05 00:30:48 +00:00
bevy_gizmos Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
bevy_gltf Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
bevy_hierarchy Fix permissions of rust source files (#16310) 2024-11-09 16:34:38 +00:00
bevy_image Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
bevy_input Use Name component for gamepad (#16233) 2024-11-05 00:30:48 +00:00
bevy_internal Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
bevy_log Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
bevy_macro_utils Modify derive_label to support no_std environments (#15465) 2024-09-27 20:23:26 +00:00
bevy_math Add more Glam types and constructors to prelude (#16261) 2024-11-11 18:47:16 +00:00
bevy_mesh Upgrade to wgpu 23 (#15988) 2024-11-05 21:18:48 +00:00
bevy_mikktspace Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
bevy_pbr Do not re-check visibility or re-render shadow maps for point and spot lights for each view (#15156) 2024-11-11 18:49:09 +00:00
bevy_picking Fix typos in bevy_picking module docs (#16265) 2024-11-08 01:15:44 +00:00
bevy_ptr Reduce compile time of bevy_ptr::OwnedPtr::make function (#15644) 2024-10-28 21:15:00 +00:00
bevy_reflect bevy_reflect: Add ReflectDeserializerProcessor (#15482) 2024-11-11 18:46:23 +00:00
bevy_remote BRP System Ordering (#16198) 2024-11-05 21:05:11 +00:00
bevy_render Do not re-check visibility or re-render shadow maps for point and spot lights for each view (#15156) 2024-11-11 18:49:09 +00:00
bevy_scene fix: add reflect to SceneInstanceReady and other observers/events (#16018) 2024-10-20 13:51:41 +00:00
bevy_sprite Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
bevy_state Fix typo in bevy_ecs (#16195) 2024-10-31 19:20:01 +00:00
bevy_tasks Resolve unused_qualifications warnings (#16001) 2024-10-19 16:59:58 +00:00
bevy_text Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
bevy_time Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
bevy_transform Improved the global transform api to access rotation and scale (#16211) 2024-11-04 15:35:16 +00:00
bevy_ui Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
bevy_utils More #[doc(fake_variadic)] goodness (#16108) 2024-10-27 19:01:50 +00:00
bevy_window Support prefers_home_indicator_hidden (#16005) 2024-10-31 16:09:30 +00:00
bevy_winit Handle failed cursor grab mode changes so that the cursor grab mode change can be attempted again (#16293) 2024-11-09 23:30:57 +00:00