bevy/crates/bevy_pbr/src
Patrick Walton 16531fb3e3
Implement GPU frustum culling. (#12889)
This commit implements opt-in GPU frustum culling, built on top of the
infrastructure in https://github.com/bevyengine/bevy/pull/12773. To
enable it on a camera, add the `GpuCulling` component to it. To
additionally disable CPU frustum culling, add the `NoCpuCulling`
component. Note that adding `GpuCulling` without `NoCpuCulling`
*currently* does nothing useful. The reason why `GpuCulling` doesn't
automatically imply `NoCpuCulling` is that I intend to follow this patch
up with GPU two-phase occlusion culling, and CPU frustum culling plus
GPU occlusion culling seems like a very commonly-desired mode.

Adding the `GpuCulling` component to a view puts that view into
*indirect mode*. This mode makes all drawcalls indirect, relying on the
mesh preprocessing shader to allocate instances dynamically. In indirect
mode, the `PreprocessWorkItem` `output_index` points not to a
`MeshUniform` instance slot but instead to a set of `wgpu`
`IndirectParameters`, from which it allocates an instance slot
dynamically if frustum culling succeeds. Batch building has been updated
to allocate and track indirect parameter slots, and the AABBs are now
supplied to the GPU as `MeshCullingData`.

A small amount of code relating to the frustum culling has been borrowed
from meshlets and moved into `maths.wgsl`. Note that standard Bevy
frustum culling uses AABBs, while meshlets use bounding spheres; this
means that not as much code can be shared as one might think.

This patch doesn't provide any way to perform GPU culling on shadow
maps, to avoid making this patch bigger than it already is. That can be
a followup.

## Changelog

### Added

* Frustum culling can now optionally be done on the GPU. To enable it,
add the `GpuCulling` component to a camera.
* To disable CPU frustum culling, add `NoCpuCulling` to a camera. Note
that `GpuCulling` doesn't automatically imply `NoCpuCulling`.
2024-04-28 12:50:00 +00:00
..
deferred Implement percentage-closer filtering (PCF) for point lights. (#12910) 2024-04-10 20:16:08 +00:00
light chore: fix some comments (#13083) 2024-04-25 19:09:16 +00:00
light_probe Implement clone for most bundles. (#12993) 2024-04-16 16:37:09 +00:00
lightmap Generate MeshUniforms on the GPU via compute shader where available. (#12773) 2024-04-10 05:33:32 +00:00
meshlet Restore dragons to their seat of power (#13124) 2024-04-28 07:20:16 +00:00
prepass Meshlet LOD-compatible two-pass occlusion culling (#12898) 2024-04-28 05:30:20 +00:00
render Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
ssao Implement clone for most bundles. (#12993) 2024-04-16 16:37:09 +00:00
bundle.rs Implement clone for most bundles. (#12993) 2024-04-16 16:37:09 +00:00
extended_material.rs Add missing Default impl to ExtendedMaterial. (#13008) 2024-04-18 12:57:14 +00:00
fog.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
lib.rs Fix CameraProjection panic and improve CameraProjectionPlugin (#11808) 2024-04-26 23:52:09 +00:00
material.rs Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
parallax.rs bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
pbr_material.rs Fix beta lints (#12980) 2024-04-16 02:46:46 +00:00
wireframe.rs Use WireframeColor to override global color (#13034) 2024-04-20 13:59:12 +00:00