|
| 1 | +When it comes to pushing hardware to support larger scenes and more detailed meshes, "simply draw less stuff" is a tried-and-true strategy. |
| 2 | +These techniques are collectively referred to as "culling": we can save work whenever we can determine "this doesn't need to be drawn" for cheaper than it would cost to actually perform the draw. |
| 3 | + |
| 4 | +**Occlusion culling** is the idea that we don't need to draw something that's completely blocked by other opaque objects, |
| 5 | +from the perspective of the camera. |
| 6 | +That makes sense! We don't need to draw a person hidden behind a wall, even if they're within the range used for frustum culling. |
| 7 | + |
| 8 | +Before you worry too much: we're already checking for this category of wasted work in some form, via the use of a **depth prepass**. |
| 9 | +A depth prepass renders the scene with a simplified shader, recording only the depth (distance from the camera) of each object into the 2-dimensional depth buffer. |
| 10 | +Then, during the more expensive main pass, objects that ended up behind something else during this simpler calculation can be skipped. |
| 11 | +Because of this approach, we can avoid most fragment shading costs (dominated by textures and lighting) for occluded objects, but the vertex shading overhead is still present, in addition to the inherent cost of this fragment testing process. |
| 12 | + |
| 13 | +We can do better than that. |
| 14 | +As [PR #17413] lays out, we're adopting the modern two-phase occlusion culling (in contrast to a traditional potentially visible sets design) already used by our virtual geometry rendering system, because it works well with the GPU-driven rendering architecture that we've established during this cycle! |
| 15 | + |
| 16 | +For now, this feature is marked as experimental, due to known precision issues that can mark meshes as occluded even when they're not. |
| 17 | +In practice, we're not convinced that this is a serious concern, so please let us know how it goes! |
| 18 | +To try out the new mesh occlusion culling, add the [`DepthPrepass`] and [`OcclusionCulling`] components to your camera. |
| 19 | + |
| 20 | +As we said above, the check has to be faster than simply drawing the thing: occlusion culling won't be faster on all scenes. |
| 21 | +Small scenes, or those using simpler non-PBR rendering are particularly likely to be slower with occlusion culling turned on. |
| 22 | +Like always: you need to measure your performance to improve it. |
| 23 | + |
| 24 | +If you're a rendering engineer who'd like to help us resolve these precision issues and stabilize this feature, we're looking to borrow from Hans-Kristian Arntzen's design in [Granite]. |
| 25 | +Chime in at [issue #14062] (and read our [Contributing Guide]) and we can help you get started. |
| 26 | + |
| 27 | +[PR #17413]: https://github.com/bevyengine/bevy/pull/17413 |
| 28 | +[`DepthPrepass`]: https://dev-docs.bevyengine.org/bevy/core_pipeline/prepass/struct.DepthPrepass.html |
| 29 | +[`OcclusionCulling`]: https://dev-docs.bevyengine.org/bevy/render/experimental/occlusion_culling/struct.OcclusionCulling.html |
| 30 | +[issue #14062]: https://github.com/bevyengine/bevy/issues/14062 |
| 31 | +[Granite]: https://github.com/Themaister/Granite |
| 32 | +[Contributing Guide]: https://bevyengine.org/learn/contribute/introduction/ |
0 commit comments