05 Data becomes vertices
The w of gl_Position: perspective divide
The whole canvas is −1…1 in normalized device coordinates. Change w for the top two vertices and see how the GPU divides by it.
0.54
-1.51.5
Exercise
Runs once per vertexDrag numbers, or edit the code
JS side
gl_Position is a vec4; the GPU divides xy by w. Between vertices with different w, interpolation is perspective-corrected too.
Try it
- Set the top w to 3: the square becomes a trapezoid
- Turn on “Multiply xy by w”: the shape stays, but the checkerboard warps
- Set z to 1.5: the part out of range is clipped