diff --git a/assets/custom_shader.wgsl b/assets/custom_shader.wgsl index f7d5ad3a..bbf11f9f 100644 --- a/assets/custom_shader.wgsl +++ b/assets/custom_shader.wgsl @@ -2,6 +2,14 @@ #import bevy_ecs_tilemap::vertex_output MeshVertexOutput #import bevy_sprite::mesh2d_view_bindings globals +struct MyMaterial { + brightness: f32, + _padding: vec3 +}; + +@group(3) @binding(0) +var material: MyMaterial; + fn hsv2rgb(c: vec3) -> vec3 { let K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); @@ -14,5 +22,5 @@ fn fragment(in: MeshVertexOutput) -> @location(0) vec4 { let color = process_fragment(in); let hsv = vec3(abs(sin(globals.time)), 1.0, 1.0); - return vec4(color.rgb + hsv2rgb(hsv), color.a); + return vec4((color.rgb + hsv2rgb(hsv)) * material.brightness, color.a); } \ No newline at end of file diff --git a/examples/custom_shader.rs b/examples/custom_shader.rs index 623d99dc..361cb80e 100644 --- a/examples/custom_shader.rs +++ b/examples/custom_shader.rs @@ -8,7 +8,13 @@ mod helpers; #[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone, Default)] #[uuid = "31575692-a956-4762-98e2-5d457f552d0a"] -pub struct MyMaterial {} +pub struct MyMaterial { + #[uniform(0)] + brightness: f32, + // webgl2 requires 16 byte alignment + #[uniform(0)] + _padding: Vec3, +} impl MaterialTilemap for MyMaterial { fn fragment_shader() -> bevy::render::render_resource::ShaderRef { @@ -23,7 +29,10 @@ fn startup( ) { commands.spawn(Camera2dBundle::default()); - let my_material_handle = materials.add(MyMaterial {}); + let my_material_handle = materials.add(MyMaterial { + brightness: 0.5, + ..default() + }); let texture_handle: Handle = asset_server.load("tiles.png"); diff --git a/src/render/material.rs b/src/render/material.rs index daf03cf2..f1643696 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -199,6 +199,7 @@ where self.tilemap_pipeline.view_layout.clone(), self.tilemap_pipeline.mesh_layout.clone(), self.tilemap_pipeline.material_layout.clone(), + self.material_tilemap_layout.clone(), ]; M::specialize(&mut descriptor, key);