struct VertexOutput { @builtin(position) clip_position: vec4, @location(0) uv: vec2 } const QUAD_VERTICES = array,4>( vec2(0.0, 0.0), vec2(2.0, 0.0), vec2(0.0, 2.0), vec2(2.0, 2.0), ); const QUAD_UVS = array,4>( vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(0.0, 0.0), vec2(1.0, 0.0), ); @group(0) @binding(0) var canvas_texture: texture_2d; @group(0) @binding(1) var canvas_sampler: sampler; @group(1) @binding(0) var rect: vec4; @vertex fn vs_main( @builtin(vertex_index) index: u32, ) -> VertexOutput { var out: VertexOutput; let model = QUAD_VERTICES[index]; out.uv = QUAD_UVS[index]; out.clip_position = vec4( -1.0 + (model.x * rect.z), -1.0 + (model.y * rect.w), 0.0, 1.0); return out; } @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4 { return textureSample(canvas_texture, canvas_sampler, in.uv); }