Short answer
WGSL (and the whole GPU pipeline that WebGPU/WGPU sits on top of) has its clip–space origin fixed in the centre of the screen:
clip-x : −1 → left, +1 → right
clip-y : −1 → top, +1 → bottom
You can’t change that convention, so the only way to work with a “Top-Left = (0, 0), grow right/down” system is to convert your own 2-D coordinates to that clip-space before you hand them to the rasteriser.
Below are two common ways to do that.
──────────────────────────────────
- Coordinates already normalised to 0-1
──────────────────────────────────
If the positions you give to the vertex shader are in the range
(0, 0) … (1, 1) with (0, 0) in the top-left corner, you only need a scale and a flip:
clipX = 2screenX – 1
clipY = 1 – 2screenY // the minus sign flips Y
WGSL:
struct VertexInput {
@location(0) pos : vec2, // 0-1, top-left-origin
@location(1) colour: vec3,
};
struct VertexOutput {
@builtin(position) clip : vec4,
@location(0) colour : vec3,
};
@vertex
fn vs_main(v: VertexInput) -> VertexOutput {
var out: VertexOutput;
let ndc = vec2(
v.pos.x * 2.0 - 1.0,
1.0 - v.pos.y * 2.0
);
out.clip = vec4(ndc, 0.0, 1.0);
out.colour = v.colour;
return out;
}
──────────────────────────────────
2. Coordinates are in pixels (need the window size)
──────────────────────────────────
If your vertex positions are literal pixel units, supply the window resolution as a uniform (or a push-constant if you have them) and divide:
struct Uniforms { resolution: vec2; };
@group(0) @binding(0) var u: Uniforms;
@vertex
fn vs_main(v: VertexInput) -> VertexOutput {
var out: VertexOutput;
let xy_norm = v.pos / u.resolution; // 0-1 range
let ndc = vec2<f32>(
xy_norm.x * 2.0 - 1.0,
1.0 - xy_norm.y * 2.0
);
out.clip = vec4<f32>(ndc, 0.0, 1.0);
out.colour = v.colour;
return out;
}
──────────────────────────────────
(Why not change the viewport instead?)
──────────────────────────────────
WebGPU’s setViewport lets you flip Y by giving a negative height:
pass.setViewport(0.0, f32(height), f32(width), -f32(height), 0.0, 1.0);
but that still expects clip-space Y of +1 at the bottom and −1 at the top.
You’d merely be moving the flip from the shader to the fixed-function viewport step; you’d still need the 0-1 → (−1…+1) scaling, so most people just do the two-line conversion in the vertex shader.
──────────────────────────────────
Take-away
──────────────────────────────────
• Clip space is immutable; do the conversion yourself.
• Scale from 0-1 (or pixels ÷ resolution) to −1…+1.
• Flip Y by y = 1 − 2*y.
Once you’ve done that, (0, 0) is top-left in your input coordinates, and the rendered output will appear exactly as you expect.