01 SDF/

SIGNED DISTANCE FIELDS

A raymarched torus shaded with a wireframe-ish distance grid.

SDF: dithered still of the signed distance fields scene

sdf/readme.md

Approach

A single torus, described by a two-line distance function, sphere-traced in a fragment shader. The interesting part is the shading: instead of a texture, the surface is parameterised by its own angles and a grid is drawn analytically in that space, so lines stay one pixel wide at any distance.

Techniques

  • Sphere tracing with relaxed over-stepping and a final bisection.
  • Normals from a tetrahedral central-difference stencil (four taps, not six).
  • Screen-space derivative (fwidth) based line antialiasing for the grid.

What to look at

The grid lines thin and thicken with curvature — that is the derivative-based antialiasing doing its job, not a texture mip.