docs/bevy/release-content/release-notes/mesh_shaders.md 2.2 K · 48 lines · raw · history

1 ---
2 title: Mesh Shaders.
3 pull_requests: [25627]
4 ---
5
6 Mesh shaders are now integrated with Bevy's pipeline cache and are available for advanced users to take advantage of.
7 Mesh shaders can be used to render
8
9 - Meshlets generated using tools like [meshoptimizer](https://meshoptimizer.org/)
10 - Procedural grass with dynamic level-of-detail, [as seen here](https://gpuopen.com/learn/mesh_shaders/mesh_shaders-procedural_grass_rendering/)
11 - Voxels, like [nvidium](https://github.com/MCRcortex/nvidium)
12 - Particles
13 - and more
14
15 Mesh shaders, at a high level, replace the classic vertex shader with a compute shader.
16 This allows generating geometry directly on the GPU and passing those generated primitives directly to the fragment shader without using multiple pipelines or intermediary buffers (to pass data from a compute shader to a render pipeline).
17
18 A `MeshPipeline` contains:
19
20 - an optional task shader (also known as amplification shader)
21 - a mesh shader
22 - a fragment shader
23
24 The new `MeshPipelineDescriptor` can be used to define a `MeshPipeline`.
25 That `MeshPipeline` is then used as a `RenderPipeline`, which allows the re-use of Bevy's lower level rendering APIs such as `RenderContext::begin_tracked_render_pass` to take advantage of the new `draw_mesh_tasks` APIs.
26
27 ```rust
28 let mut pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
29 label: Some("custom_mesh_shader_pass"),
30 color_attachments: &[Some(target.get_color_attachment())],
31 depth_stencil_attachment: Some(depth.get_attachment(StoreOp::Store)),
32 ..default()
33 });
34
35 pass.set_render_pipeline(mesh_pipeline);
36 pass.set_bind_group(0, &bind_group, &[view_uniform_offset.offset]);
37
38 // draw_mesh_tasks dispatches the task shader if there is one,
39 // or dispatches the mesh shader if there is no task shader.
40 pass.draw_mesh_tasks(1, 1, 1);
41 ```
42
43 It is notable that mesh shaders are an advanced graphics approach with platform-specific performance considerations, and that this is the initial base support for the feature.
44 Higher level user APIs, and easy integration with Bevy's `StandardMaterial`, are left to future work.
45
46 Mesh shaders are not supported on web platforms.
47
48 Check out the new `mesh_shader_intro` example for more usage examples.