12 From picture to recipe
Five layers: from picture to code
Almost every 2D shader splits into five layers: space, shape, edge, paint and time. Change one layer at a time and watch what changes.
ExerciseTune values
Read the target layer by layer: how is space changed? which shape? filled or outlined? what drives the colour?
Runs once per pixelDrag numbers, or edit the code
JS side
gl.uniform2f(uResolution, …, …)Look at a picture and ask five questions: ① how is space transformed? ② what is the distance to the shape? ③ how does distance become light and dark? ④ where does the colour come from? ⑤ what moves? Each answer is a line or two of code.
Try it
- Change one layer at a time and say what changed in the picture
- Open the pixel debugger and show d on the canvas: the shape layer only computes a distance map
- Switch space to “repeat”, then change the shape: the two layers don’t affect each other