struct Uniforms { camera: vec2f, zooms: vec2f } @group(0) @binding(0) var uniforms : Uniforms; struct VertexOutput { @location(0) tex_pos: vec2f, @location(1) color: vec4f, @location(2) effect: u32, @builtin(position) pos: vec4f } @vertex fn vs_main( @location(0) pos: vec2f, @location(1) color: vec4f, @location(2) tex_pos: vec2f, @location(3) effect: u32 ) -> VertexOutput { var screen_pos: vec4f; if (effect & 1) == 0 { screen_pos = vec4f(pos, 0, 1); } else { screen_pos = vec4f((pos - uniforms.camera) * uniforms.zooms, 0, 1); } var out = VertexOutput( tex_pos, color, effect, screen_pos ); return out; } @group(1) @binding(0) var t_diffuse: texture_2d; @group(1) @binding(1) var s_diffuse: sampler; @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f { var tex_col = textureSample(t_diffuse, s_diffuse, in.tex_pos); var color = vec4f((tex_col.rgb * tex_col.a) + (in.color.rgb * in.color.a), tex_col.a + in.color.a); // Grayscale if (in.effect & 2) != 0 { var v = (color.r*0.299) + (color.g*0.587) + (color.b*0.114); color = vec4f(v, v, v, color.a); } return color; }