playfield · docs

docs · 03

Distance

A signed distance says how far each pixel is from a shape. One number gives fills, outlines, glows and 3D.

A signed distance is, for each pixel, how far it is from a shape: negative inside, positive outside and 0 on the edge. It is the most useful single idea in shaders, and almost every graph in Playfield uses one.

Every shape node in Playfield (a circle, a box, a star, text and the rest) has a Distance output.

One number, many looks

The same distance d draws very different things:

Look What it does In maths
Fill Colours the inside d < 0
Outline A line along the edge, w wide abs(d) < w
Glow Light that fades with distance exp(-k * max(d, 0))
Rounded A bigger shape with round corners d - r
Shell A hollow ring abs(d) - w
Contours Lines at equal distances fract(d * n)

You rarely type these: Distance Fill and Distance Glow take a distance and do it for you, with sliders for the width, the softness and the colour.

Combining shapes

  • Union (both shapes): the smaller of two distances, min(a, b).
  • Intersection (only where they overlap): the larger, max(a, b).
  • Cut b out of a: max(a, -b).
  • A smooth union blends two shapes like liquid, as in metaballs.

Distances keep their meaning after you combine them, so a glow or an outline still works on the result. That is why distances are better than masks.

In 3D

A 3D scene is a distance too: from any point in space, how far to the nearest surface. Sphere tracing draws it. From the eye, a ray steps forward by that distance again and again. Each step is safe, because nothing is closer than the distance, and the steps shrink as the ray nears a surface, until it hits.

Your email, to tell you when Playfield opens and about big updates. Nothing else; unsubscribe any time. Privacy