bevy/crates/bevy_core_pipeline/src
Robert Swain e6405bb7b4
Use GpuArrayBuffer for MeshUniform (#9254)
# Objective

- Reduce the number of rebindings to enable batching of draw commands

## Solution

- Use the new `GpuArrayBuffer` for `MeshUniform` data to store all
`MeshUniform` data in arrays within fewer bindings
- Sort opaque/alpha mask prepass, opaque/alpha mask main, and shadow
phases also by the batch per-object data binding dynamic offset to
improve performance on WebGL2.

---

## Changelog

- Changed: Per-object `MeshUniform` data is now managed by
`GpuArrayBuffer` as arrays in buffers that need to be indexed into.

## Migration Guide

Accessing the `model` member of an individual mesh object's shader
`Mesh` struct the old way where each `MeshUniform` was stored at its own
dynamic offset:
```rust
struct Vertex {
    @location(0) position: vec3<f32>,
};

fn vertex(vertex: Vertex) -> VertexOutput {
    var out: VertexOutput;
    out.clip_position = mesh_position_local_to_clip(
        mesh.model,
        vec4<f32>(vertex.position, 1.0)
    );
    return out;
}
```

The new way where one needs to index into the array of `Mesh`es for the
batch:
```rust
struct Vertex {
    @builtin(instance_index) instance_index: u32,
    @location(0) position: vec3<f32>,
};

fn vertex(vertex: Vertex) -> VertexOutput {
    var out: VertexOutput;
    out.clip_position = mesh_position_local_to_clip(
        mesh[vertex.instance_index].model,
        vec4<f32>(vertex.position, 1.0)
    );
    return out;
}
```
Note that using the instance_index is the default way to pass the
per-object index into the shader, but if you wish to do custom rendering
approaches you can pass it in however you like.

---------

Co-authored-by: robtfm <50659922+robtfm@users.noreply.github.com>
Co-authored-by: Elabajaba <Elabajaba@users.noreply.github.com>
2023-07-30 13:17:08 +00:00
..
blit improve shader import model (#5703) 2023-06-27 00:29:22 +00:00
bloom Return URect instead of (UVec2, UVec2) in Camera::physical_viewport_rect (#9085) 2023-07-15 21:25:22 +00:00
contrast_adaptive_sharpening Fix CAS shader with explicit FullscreenVertexOutput import (#8993) 2023-06-29 19:56:57 +00:00
core_2d bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
core_3d Use GpuArrayBuffer for MeshUniform (#9254) 2023-07-30 13:17:08 +00:00
fullscreen_vertex_shader Built-in skybox (#8275) 2023-04-02 10:57:12 +00:00
fxaa bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
prepass Use GpuArrayBuffer for MeshUniform (#9254) 2023-07-30 13:17:08 +00:00
skybox improve shader import model (#5703) 2023-06-27 00:29:22 +00:00
taa Fix typos throughout the project (#9090) 2023-07-10 00:11:51 +00:00
tonemapping bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
upscaling Apply codebase changes in preparation for StandardMaterial transmission (#8704) 2023-05-30 14:21:53 +00:00
clear_color.rs Document ClearColorConfig (#9288) 2023-07-29 22:22:49 +00:00
lib.rs Allow tuples and single plugins in add_plugins, deprecate add_plugin (#8097) 2023-06-21 20:51:03 +00:00
msaa_writeback.rs Use RenderGraphApp in more places (#8298) 2023-04-05 20:57:56 +00:00