Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#import bevy_pbr::{
2 mesh_functions,
3 view_transformations::position_world_to_clip
4}
6@group(2) @binding(0) var<storage, read> colors: array<vec4<f32>, 5>;
8struct Vertex {
9 @builtin(instance_index) instance_index: u32,
10 @location(0) position: vec3<f32>,
11};
13struct VertexOutput {
14 @builtin(position) clip_position: vec4<f32>,
15 @location(0) world_position: vec4<f32>,
16 @location(1) color: vec4<f32>,
17};
19@vertex
20fn vertex(vertex: Vertex) -> VertexOutput {
21 var out: VertexOutput;
22 var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
23 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex.position, 1.0));
24 out.clip_position = position_world_to_clip(out.world_position.xyz);
26 // We have 5 colors in the storage buffer, but potentially many instances of the mesh, so
27 // we use the instance index to select a color from the storage buffer.
28 out.color = colors[vertex.instance_index % 5];
30 return out;
33@fragment
34fn fragment(
35 mesh: VertexOutput,
36) -> @location(0) vec4<f32> {
37 return mesh.color;
Contents