summaryrefslogtreecommitdiff
path: root/src/shaders/render/fullscreen_uv_vs.wgsl
blob: 5f7616004a9a698d84cefb39b5a6c32ddebfeb1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Common vertex shader for fullscreen post-processing effects.
// Draws a single triangle that covers the entire screen.
//
// Screen-space convention: Y-UP, origin at BOTTOM-LEFT
//   uv  in [0,1]:   (0,0) = bottom-left,  (1,1) = top-right
//   st  in [-1,1]:  NDC directly, y-up
//
// WebGPU textures are Y-DOWN ((0,0) at top-left).
// Use textureSampleYUp() instead of textureSample() when sampling with uv.
struct VertexOutput {
    @builtin(position) position: vec4f,  // in pixel screen units
    @location(0) uv: vec2f,  // in [0, 1]
    @location(1) st: vec2f,  // in [-1, 1]
};

@vertex fn vs_main(@builtin(vertex_index) i: u32) -> VertexOutput {
    let pos = array<vec4f, 3>(vec4f(-1, -1, 0, 0.), vec4f(3, -1, 2., 0.), vec4f(-1, 3, 0, 2.));
    var out: VertexOutput;
    out.position = vec4f(pos[i].xy, 0.0, 1.0);
    out.uv = pos[i].zw;
    out.st = pos[i].xy;
    return out;
}

// Sample a texture using y-up UV coordinates (uv.y=0 at bottom).
// Flips Y to match WebGPU texture convention (texel (0,0) at top-left).
fn textureSampleYUp(tex: texture_2d<f32>, s: sampler, uv: vec2f) -> vec4f {
    return textureSample(tex, s, vec2f(uv.x, 1.0 - uv.y));
}