@group(0) @binding(0) var source_tex: texture_2d<f32>;
@group(0) @binding(1) var source_sampler: sampler;
struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOut {
let positions = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -3.0),
vec2<f32>(3.0, 1.0),
vec2<f32>(-1.0, 1.0),
);
let position = positions[vertex_index];
var out: VertexOut;
out.position = vec4<f32>(position, 0.0, 1.0);
out.uv = position * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5, 0.5);
return out;
}
@fragment
fn fs_main(in: VertexOut) -> @location(0) vec4<f32> {
let pixel = vec2<u32>(floor(in.position.xy));
let source_size = textureDimensions(source_tex);
if (pixel.x >= source_size.x || pixel.y >= source_size.y) {
return vec4<f32>(0.0);
}
return textureLoad(source_tex, vec2<i32>(pixel), 0);
}