struct VertexInput { @builtin(vertex_index) vertex_index: u32, @location(0) top_left: vec3, @location(1) bottom_right: vec2, @location(2) tex_top_left: vec2, @location(3) tex_bottom_right: vec2, @location(4) color: vec4, } struct Matrix { v: mat4x4, } @group(0) @binding(0) var ortho: Matrix; struct VertexOutput { @builtin(position) clip_position: vec4, @location(0) tex_pos: vec2, @location(1) color: vec4, } @vertex fn vs_main(in: VertexInput) -> VertexOutput { var out: VertexOutput; var pos: vec2; var left: f32 = in.top_left.x; var right: f32 = in.bottom_right.x; var top: f32 = in.top_left.y; var bottom: f32 = in.bottom_right.y; switch (in.vertex_index) { case 0u: { pos = vec2(left, top); out.tex_pos = in.tex_top_left; break; } case 1u: { pos = vec2(right, top); out.tex_pos = vec2(in.tex_bottom_right.x, in.tex_top_left.y); break; } case 2u: { pos = vec2(left, bottom); out.tex_pos = vec2(in.tex_top_left.x, in.tex_bottom_right.y); break; } case 3u: { pos = vec2(right, bottom); out.tex_pos = in.tex_bottom_right; break; } default: {} } out.clip_position = ortho.v * vec4(pos, in.top_left.z, 1.0); out.color = in.color; return out; } @group(0) @binding(1) var texture: texture_2d; @group(0) @binding(2) var tex_sampler: sampler; @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4 { var alpha: f32 = textureSample(texture, tex_sampler, in.tex_pos).r; return vec4(in.color.rgb, in.color.a * alpha); }