This example is running in WebGL2 and should work in most browsers. You can check the WebGPU examples here.
//! A shader that reads a mesh's custom vertex attribute.
use ;
/// This example uses a shader source file from the assets subdirectory
const SHADER_ASSET_PATH: &str = "shaders/custom_vertex_attribute.wgsl";
// A "high" random id should be used for custom attributes to ensure consistent sorting and avoid collisions with other attributes.
// See the MeshVertexAttribute docs for more info.
const ATTRIBUTE_BLEND_COLOR: MeshVertexAttribute =
;
new
/// set up a simple 3D scene
// This is the struct that will be passed to your shader
#import bevy_pbr::mesh_functions::{get_world_from_local, mesh_position_local_to_clip}
struct CustomMaterial {
color: vec4<f32>,
};
(2) (0) var<uniform> material: CustomMaterial;
struct Vertex {
(instance_index) instance_index: u32,
(0) position: vec3<f32>,
(1) blend_color: vec4<f32>,
};
struct VertexOutput {
(position) clip_position: vec4<f32>,
(0) blend_color: vec4<f32>,
};
fn -> VertexOutput {
var out: VertexOutput;
out.clip_position = ,
);
out.blend_color = vertex.blend_color;
return out;
}
struct FragmentInput {
(0) blend_color: vec4<f32>,
};
fn -> (0) vec4<f32> {
return material.color * input.blend_color;
}