bevy/crates/bevy_render/src
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
..
batching Type safe retained render world (#15756) 2024-10-10 18:47:04 +00:00
camera Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
diagnostic Ensure Bevy's rendering byte usage is little-endian (#15750) 2024-10-08 22:43:35 +00:00
mesh Revert default mesh materials (#15930) 2024-10-15 19:47:40 +00:00
primitives Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
render_graph More #[doc(fake_variadic)] goodness (#16108) 2024-10-27 19:01:50 +00:00
render_phase Make BinnedRenderPhase fields for accessing batchable and unbatchable entities public (#16142) 2024-11-07 18:03:47 +00:00
render_resource Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
renderer Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
texture 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
view Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
alpha.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
color_operations.wgsl move wgsl color operations from bevy_pbr to bevy_render (#13209) 2024-05-04 10:30:23 +00:00
extract_component.rs Remove ExtractComponent::Out (#15926) 2024-10-15 23:42:35 +00:00
extract_instances.rs Type safe retained render world (#15756) 2024-10-10 18:47:04 +00:00
extract_param.rs Implement WorldQuery for MainWorld and RenderWorld components (#15745) 2024-10-13 20:58:46 +00:00
extract_resource.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
globals.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
globals.wgsl
gpu_component_array_buffer.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
gpu_readback.rs Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
lib.rs Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
maths.wgsl add tonemapping LUT bindings for sprite and mesh2d pipelines (#13262) 2024-05-28 12:09:26 +00:00
pipelined_rendering.rs Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
render_asset.rs Remove thiserror from bevy_render (#15765) 2024-10-09 14:26:28 +00:00
settings.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
spatial_bundle.rs Deprecate SpatialBundle (#15830) 2024-10-13 17:28:22 +00:00
storage.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
sync_component.rs Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
sync_world.rs Derive same attributes as MainEntity for RenderEntity (#16191) 2024-10-31 14:56:27 +00:00