Shader Learn

02 Drawing shapes with math

fwidth: edges sharp at any zoom

The left half uses a fixed width, the right half fwidth. Zoom the coordinates and compare.

Fixed widthfwidth
160
0.0010.1

Runs once per pixelDrag numbers, or edit the code

JS sidegl.uniform2f(uResolution, …, …)

fwidth(d) is how much d changes between neighbouring pixels; as the smoothstep width it keeps edges one pixel soft at any zoom.

Try it

  • Zoom to 40 and compare the halves
  • Widen the fixed width on the left: far away gets blurry; narrow it: close up gets jaggy