00 Prologue: how a GPU paints
Where does a shader’s result show up?
On the left is a real HTML canvas; the GPU paints its colours.
01
01
01
01
Exercise
Drag the underlined numbers left and rightDrag numbers, or edit the code
void main() { vec3 color = vec3(, , ); gl_FragColor = vec4(color, );}
- JS sends data
- GPU computes colours
- canvas shows them
canvasA bitmap drawing surface in the pageWebGLThe API JS uses to hand data and shaders to the GPUshaderA small program that runs on the GPU, written in GLSLDrag the numbers left and right, right in the code; the fourth is the opacity. Every lesson’s code works this way, and you can also just type.
JS side
A canvas is a drawing surface in the page; WebGL lets the GPU write colours into it.
Try it
- Make the canvas pure red
- What colour do you get when all three numbers are equal?