This example is running in WebGL2 and should work in most browsers. You can check the WebGPU examples here.
//! A shader that uses "shaders defs", which selectively toggle parts of a shader.
use ;
/// This example uses a shader source file from the assets subdirectory
const SHADER_ASSET_PATH: &str = "shaders/shader_defs.wgsl";
/// set up a simple 3D scene
// This is the struct that will be passed to your shader
// This key is used to identify a specific permutation of this material pipeline.
// In this case, we specialize on whether or not to configure the "IS_RED" shader def.
// Specialization keys should be kept as small / cheap to hash as possible,
// as they will be used to look up the pipeline for each drawn entity with this material type.
#import bevy_pbr::forward_io::VertexOutput
struct CustomMaterial {
color: vec4<f32>,
};
(2) (0) var<uniform> material: CustomMaterial;
fn -> (0) vec4<f32> {
#ifdef IS_RED
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
#else
return material.color;
#endif
}