1struct FullscreenVertexOutput {2 @builtin(position)3 position: vec4<f32>,4 @location(0)5 uv: vec2<f32>,6};8// This vertex shader produces the following, when drawn using indices 0..3:9//10// 1 | 0-----x.....211// 0 | | s | . ´12// -1 | x_____x´13// -2 | : .´14// -3 | 1´15// +---------------16// -1 0 1 2 317//18// The axes are clip-space x and y. The region marked s is the visible region.19// The digits in the corners of the right-angled triangle are the vertex20// indices.21//22// The top-left has UV 0,0, the bottom-left has 0,2, and the top-right has 2,0.23// This means that the UV gets interpolated to 1,1 at the bottom-right corner24// of the clip-space rectangle that is at 1,-1 in clip space.25@vertex26fn fullscreen_vertex_shader(@builtin(vertex_index) vertex_index: u32) -> FullscreenVertexOutput {27 // See the explanation above for how this works28 let uv = vec2<f32>(f32(vertex_index >> 1u), f32(vertex_index & 1u)) * 2.0;29 let clip_position = vec4<f32>(uv * vec2<f32>(2.0, -2.0) + vec2<f32>(-1.0, 1.0), 0.0, 1.0);31 return FullscreenVertexOutput(clip_position, uv);32}