struct VertexOutput {
    @builtin(position) position: vec4<f32>,
    @location(0) uv: vec2<f32>,
}

struct Uniforms {
    rect: vec4<f32>,
}

@group(0) @binding(0)
var t: texture_2d<f32>;

@group(0) @binding(1)
var s: sampler;

@group(0) @binding(2)
var<uniform> uniforms: Uniforms;

@vertex
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {
    let quad = array<vec2<f32>, 6>(
        uniforms.rect.xy,
        uniforms.rect.zy,
        uniforms.rect.xw,
        uniforms.rect.zy,
        uniforms.rect.zw,
        uniforms.rect.xw,
    );

    var out: VertexOutput;
    out.uv = vec2<f32>(0.0);
    out.uv.x = select(0.0, 2.0, in_vertex_index == 1u);
    out.uv.y = select(0.0, 2.0, in_vertex_index == 2u);
    out.position = vec4<f32>(out.uv * vec2<f32>(2.0, -2.0) + vec2<f32>(-1.0, 1.0), 1.0, 1.0);
    return out;
}

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
    return textureSample(t, s, in.uv);
}
