@group(0) @binding(0) var<uniform> scale: vec2f;
@group(0) @binding(1) var texture: texture_2d<f32>;
@group(0) @binding(2) var tex_sampler: sampler;
struct VertexOutput {
@builtin(position) position: vec4f,
@location(0) uv: vec2f,
}
@vertex
fn vs_main(
@builtin(vertex_index) index: u32,
) -> VertexOutput {
var i: u32;
if index < 3 { i = index; } else { i = 6 - index; }
var out: VertexOutput;
out.position =
vec4(
scale * vec2(
f32((i32(i) >> 1 & 1) * 2 - 1),
f32(1 - (i32(i) & 1) * 2),
),
0.0, 1.0
);
out.uv = vec2(
f32(i32(i) >> 1 & 1),
f32(i32(i) & 1),
);
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4f {
return textureSample(texture, tex_sampler, in.uv);
}