This example is running in WebGL2 and should work in most browsers. You can check the WebGPU examples here.
//! A shader that uses the GLSL shading language.
use ;
/// This example uses shader source files from the assets subdirectory
const VERTEX_SHADER_ASSET_PATH: &str = "shaders/custom_material.vert";
const FRAGMENT_SHADER_ASSET_PATH: &str = "shaders/custom_material.frag";
/// set up a simple 3D scene
// This is the struct that will be passed to your shader
/// The Material trait is very configurable, but comes with sensible defaults for all methods.
/// You only need to implement functions for features that need non-default behavior. See the Material api docs for details!
/// When using the GLSL shading language for your shader, the specialize method must be overridden.
#version 450
in vec3 Vertex_Position;
in vec3 Vertex_Normal;
in vec2 Vertex_Uv;
out vec2 v_Uv;
uniform CameraViewProj {
mat4 clip_from_world;
// Other attributes exist that can be described here.
// See full definition in: crates/bevy_render/src/view/view.wgsl
// Attributes added here must be in the same order as they are defined
// in view.wgsl, and they must be contiguous starting from the top to
// ensure they have the same layout.
//
// Needing to maintain this mapping yourself is one of the harder parts of using
// GLSL with Bevy. WGSL provides a much better user experience!
} camera_view;
struct Mesh {
mat3x4 Model;
mat4 InverseTransposeModel;
uint flags;
};
#ifdef PER_OBJECT_BUFFER_BATCH_SIZE
uniform Mesh Meshes[#{PER_OBJECT_BUFFER_BATCH_SIZE}];
#else
readonly buffer _Meshes {
Mesh Meshes[];
};
#endif // PER_OBJECT_BUFFER_BATCH_SIZE
mat4 {
return ;
}
void {
v_Uv = Vertex_Uv;
gl_Position = camera_view.clip_from_world
*
* ;
}
#version 450
in vec2 v_Uv;
out vec4 o_Target;
uniform vec4 CustomMaterial_color;
uniform texture2D CustomMaterial_texture;
uniform sampler CustomMaterial_sampler;
// wgsl modules can be imported and used in glsl
// FIXME - this doesn't work any more ...
// #import bevy_pbr::pbr_functions as PbrFuncs
void {
// o_Target = PbrFuncs::tone_mapping(Color * texture(sampler2D(CustomMaterial_texture,CustomMaterial_sampler), v_Uv));
o_Target = CustomMaterial_color * ;
}