bevy/examples/3d
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
..
3d_scene.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
3d_shapes.rs Implement percentage-closer filtering (PCF) for point lights. (#12910) 2024-04-10 20:16:08 +00:00
3d_viewport_to_world.rs separating finite and infinite 3d planes (#12426) 2024-04-18 14:13:22 +00:00
animated_material.rs Add hue traits (#12399) 2024-03-22 00:36:46 +00:00
anti_aliasing.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
atmospheric_fog.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
blend_modes.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
bloom_3d.rs Improve Bloom 3D lighting (#11981) 2024-03-07 15:20:38 +00:00
deferred_rendering.rs Implement GPU frustum culling. (#12889) 2024-04-28 12:50:00 +00:00
fog.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
generate_custom_mesh.rs Clarify comment about camera coordinate system (#13056) 2024-04-23 14:58:28 +00:00
irradiance_volumes.rs separating finite and infinite 3d planes (#12426) 2024-04-18 14:13:22 +00:00
lighting.rs Fix pink colors in examples (#12451) 2024-03-18 17:44:46 +00:00
lightmaps.rs fix example lightmaps after color migration (#12265) 2024-03-03 21:36:11 +00:00
lines.rs Intern mesh vertex buffer layouts so that we don't have to compare them over and over. (#12216) 2024-03-01 20:56:21 +00:00
load_gltf.rs New Exposure and Lighting Defaults (and calibrate examples) (#11868) 2024-02-15 20:42:48 +00:00
meshlet.rs Meshlet LOD-compatible two-pass occlusion culling (#12898) 2024-04-28 05:30:20 +00:00
motion_blur.rs Per-Object Motion Blur (#9924) 2024-04-25 01:16:02 +00:00
orthographic.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
parallax_mapping.rs Move close_on_esc to bevy_dev_tools (#12855) 2024-04-03 01:29:06 +00:00
parenting.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
pbr.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
reflection_probes.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
render_to_texture.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
shadow_biases.rs Implement percentage-closer filtering (PCF) for point lights. (#12910) 2024-04-10 20:16:08 +00:00
shadow_caster_receiver.rs Remove redundant imports (#12817) 2024-04-01 19:59:08 +00:00
skybox.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
spherical_area_lights.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
split_screen.rs Fix "dark grey" colors becoming lighter in various examples (#12333) 2024-03-06 05:19:59 +00:00
spotlight.rs Adding explanation to seeded rng used in examples (#12593) 2024-03-26 19:40:18 +00:00
ssao.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
texture.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
tonemapping.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
transmission.rs Fix green colors becoming darker in various examples (#12328) 2024-03-05 23:42:03 +00:00
transparency_3d.rs Implement alpha to coverage (A2C) support. (#12970) 2024-04-15 20:37:52 +00:00
two_passes.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
update_gltf_scene.rs New Exposure and Lighting Defaults (and calibrate examples) (#11868) 2024-02-15 20:42:48 +00:00
vertex_colors.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
wireframe.rs Use WireframeColor to override global color (#13034) 2024-04-20 13:59:12 +00:00