Combining shapes with arithmetic

SDF operator playground

Two distance functions go in, one comes out. Union is min, intersection is max, subtraction is max against a negated field — each of them a single line, with no mesh to re‑stitch and no vertices to weld. Then reach for smooth union and drag the k slider: the two shapes grow a fillet where they meet, which is the operation that makes distance fields worth the trouble.

The combined field d(p)
Drag either centre

Bands are lines of equal distance. Watch how they behave where the two shapes meet.

The resulting surface d = 0
Drag either centre
shape a shape b the result
Operator min(a, b)
0.35
0.62
0.52

The scene function live

    
Why smooth union is the interesting one the fillet

Plain min takes whichever surface is nearer, so where two shapes meet you get a crease — a hard, non‑differentiable seam, exactly what you would get by overlapping two meshes.

Smooth union replaces that hard choice with a blend that widens as the two distances approach each other. Within a band of width k around the seam it pulls the surface outward, producing a fillet that is continuous in its derivative — so the normals are continuous too, and it shades like one organic object rather than two glued ones.

There is no mesh operation that does this cheaply. Booleans on triangle meshes are notoriously fragile, and filleting the seam afterwards is a modelling job. Here it is one line and one parameter, and it works for any pair of shapes you can write down.

Pointer p
a — distance to shape a
b — distance to shape b
the operator returns
Nearer surface
One caveat worth carrying forward. min(a, b) of two exact distance fields is still an exact distance field everywhere outside the shapes — the nearest surface really is whichever one is nearer. The others are not so lucky. max and the smooth operators return a value that is a lower bound on the true distance, never larger than the truth but sometimes smaller. That is safe for sphere tracing, since an underestimate merely means a shorter step, but it does mean an intersection or a heavily blended union costs more iterations than the shapes suggest. If a raymarched scene is mysteriously slow, this is usually why.