This example demonstrates how to use a storage buffer with AsBindGroup in a custom material.
use ;
const SHADER_ASSET_PATH: &str = "shaders/storage_buffer.wgsl";
/// set up a simple 3D scene
// Update the material color by time
// Holds handles to the custom materials
;
// This struct defines the data that will be passed to your shader
#import bevy_pbr::{
mesh_functions,
view_transformations::position_world_to_clip
}
@group(#{MATERIAL_BIND_GROUP}) @binding(0) var<storage, read> colors: array<vec4<f32>, 5>;
struct Vertex {
@builtin(instance_index) instance_index: u32,
@location(0) position: vec3<f32>,
};
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
@location(0) world_position: vec4<f32>,
@location(1) color: vec4<f32>,
};
@vertex
var out: VertexOutput;
let tag = mesh_functions::;
var world_from_local = mesh_functions::;
out.world_position = mesh_functions::;
out.clip_position = ;
out.color = colors[tag];
return out;
}
@fragment
return mesh.color;
}```