bevy/crates
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
..
bevy_a11y Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_animation Expose mutable Animation Clips (#13067) 2024-04-23 14:58:08 +00:00
bevy_app Simplify runner app exit code. (#13074) 2024-04-23 20:42:00 +00:00
bevy_asset Fix Clippy lints on WASM (#13030) 2024-04-20 09:15:42 +00:00
bevy_audio Implement clone for most bundles. (#12993) 2024-04-16 16:37:09 +00:00
bevy_color Fix crates not building individually (#12948) 2024-04-14 00:06:03 +00:00
bevy_compile_test_utils Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_core Fix beta lints (#12980) 2024-04-16 02:46:46 +00:00
bevy_core_pipeline Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_derive Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_dev_tools Make AppExit more specific about exit reason. (#13022) 2024-04-22 16:48:18 +00:00
bevy_diagnostic Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
bevy_dylib Set the logo and favicon for all of Bevy's published crates (#12696) 2024-03-25 18:52:50 +00:00
bevy_dynamic_plugin Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_ecs chore: fix some comments (#13083) 2024-04-25 19:09:16 +00:00
bevy_ecs_compile_fail_tests Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_encase_derive Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_gilrs Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
bevy_gizmos Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_gltf Fix crates not building individually (#12948) 2024-04-14 00:06:03 +00:00
bevy_hierarchy fix bevy_hierarchy crate optional feature bevy_app (#12943) 2024-04-13 04:46:00 +00:00
bevy_input Added ButtonInput docs usage example (#13046) 2024-04-22 17:48:46 +00:00
bevy_internal Switch monolithic lib to module re-exports (#13059) 2024-04-22 01:32:51 +00:00
bevy_log Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
bevy_macro_utils Clean up some low level dependencies (#12858) 2024-04-08 19:45:42 +00:00
bevy_macros_compile_fail_tests Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_math Use Vec3A for 3D bounding volumes and raycasts (#13087) 2024-04-25 18:56:58 +00:00
bevy_mikktspace Enable clippy::ref_as_ptr (#12918) 2024-04-10 20:16:48 +00:00
bevy_pbr Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_ptr chore: fix some comments (#13083) 2024-04-25 19:09:16 +00:00
bevy_reflect iter_with_data (#13102) 2024-04-26 02:09:34 +00:00
bevy_reflect_compile_fail_tests Switch to ui_test in compile fail tests. (#12810) 2024-04-27 00:00:57 +00:00
bevy_render Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_scene Implement clone for most bundles. (#12993) 2024-04-16 16:37:09 +00:00
bevy_sprite Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_tasks Remove async-task as a dependency (#13071) 2024-04-23 14:57:55 +00:00
bevy_text Fix beta lints (#12980) 2024-04-16 02:46:46 +00:00
bevy_time Fix uses of "it's" vs "its". (#13033) 2024-04-19 18:17:31 +00:00
bevy_transform Fix Clippy lints on WASM (#13030) 2024-04-20 09:15:42 +00:00
bevy_ui Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
bevy_utils Improve par_iter and Parallel (#12904) 2024-04-23 12:05:34 +00:00
bevy_window Make AppExit more specific about exit reason. (#13022) 2024-04-22 16:48:18 +00:00
bevy_winit Simplify runner app exit code. (#13074) 2024-04-23 20:42:00 +00:00