Shader Learn

02 Drawing shapes with math

SDF: distances with a sign

Give distances a sign and you can unite, intersect and subtract shapes.

0.080.35
0.050.7
ExerciseTune values0%

Make a crescent moon

Runs once per pixelDrag numbers, or edit the code

JS sidegl.uniform2f(uResolution, …, …)

Signed distance: below 0 is inside, 0 is on the edge. min unites, max intersects, max(a, −b) subtracts.

Try it

  • Switch through the three combinations
  • Open the pixel debugger and check that d is negative inside the circle