Builtin variables

Builtin variables

A gl_* global is a @builtin(...) attribute on a parameter, on a class field or on the return. The attribute says which value it is and the writer decides which global that becomes, which is how one file reaches both targets.

GLSL ES 3.00TypeShadeNote
gl_Position
@builtin("position")

The same id on a vertex output. A vertex entry returning a bare vec4 carries it with nothing written.

gl_FragCoord
@builtin("position")

The same id on a fragment input. The y origin differs: this target counts from the bottom of the window and WebGPU from the top, so a shader that reads .y needs a flip of its own.

uint(gl_VertexID)
@builtin("vertex_index")

An index is a u32 here and an int there, so the read is wrapped in the declared type.

uint(gl_InstanceID)
@builtin("instance_index")

The same wrap, for the same reason.

gl_FrontFacing
@builtin("front_facing")

A bool on both targets, so the read needs no cast.

gl_FragDepth
@builtin("frag_depth")

Written as a field of the struct a fragment entry returns, beside its colour.

Two of them have no name in this surface. The front end refuses the spelling at the declaration, and the sentence below is what the WGSL backend prints for the same name, which says what to reach for instead.

GLSL ES 3.00What to write
gl_PointSize

does not exist in WGSL — WebGPU point-list primitives are always 1px. Expand an instanced quad in the vertex stage instead

gl_PointCoord

does not exist in WGSL — there is no point-sprite coordinate. Interpolate a @location(n) corner uv from the expanded quad instead

Edit this page Report a problem