Most familiar 3D models describe a surface explicitly. A polygon mesh stores vertices and the faces that connect them. A parametric patch maps coordinates such as uu and vv to positions on a surface. Both approaches answer a version of the same question: where is the geometry?

A signed distance field, or SDF, reverses the relationship. Give it any point in space and it returns a number. The magnitude is the shortest distance to the boundary; the sign classifies the point as inside or outside. The surface itself is where the answer is zero.

That change in viewpoint makes clearance queries, normals, offsets, Boolean composition, ray tracing, deformation, and learned shape families direct operations on a scalar function. This article develops the field mathematics and then connects it to Rig Cad’s hybrid SDF-and-mesh workflow.

Mesh and SDF Kernel Showcase
Project

Mesh and SDF Kernel Showcase

@p12/multi-kernel showcase
Mesh and SDF Kernel Showcase
Mesh and SDF Kernel Showcase

Compare mesh and SDF branches, then inspect how field precision and conversion affect smoothness, detail, and downstream geometry.

@p12/multi-kernel showcase
Compare mesh and SDF branches, then inspect how field precision and conversion affect smoothness, detail, and downstream geometry.

A shape defined everywhere

Let Ω\Omega be a solid region with boundary Ω\partial\Omega. First define the unsigned distance from a point to that boundary:

d(p,Ω)=minqΩpq.d(\mathbf p,\partial\Omega) =\min_{\mathbf q\in\partial\Omega}|\mathbf p-\mathbf q|.

Using the common negative-inside convention, ϕ(p)=d(p,Ω)\phi(\mathbf p)=-d(\mathbf p,\partial\Omega) when pΩ\mathbf p\in\Omega, and ϕ(p)=d(p,Ω)\phi(\mathbf p)=d(\mathbf p,\partial\Omega) when pΩ\mathbf p\notin\Omega. The opposite sign convention is also used, so implementations should always state which one they follow. With the convention above:

  • ϕ(p)<0\phi(\mathbf p)<0 means the point is inside;
  • ϕ(p)=0\phi(\mathbf p)=0 means the point is on the boundary;
  • ϕ(p)>0\phi(\mathbf p)>0 means the point is outside; and
  • ϕ(p)|\phi(\mathbf p)| is the Euclidean distance to the closest boundary point. This is richer than a generic implicit function.

For example: both x2+y2+z2r2=0x^2+y^2+z^2-r^2=0 and x2+y2+z2r=0\sqrt{x^2+y^2+z^2}-r=0 describe a sphere of radius rr. Only the second expression returns geometric distance from the sphere.

The first has the correct zero set but its values away from the surface are algebraic quantities, not distances.

Three exact examples

Simple shapes often have compact analytical SDFs.

Shape Parameters Exact SDF
Sphere Center and radius: (c,r)(\mathbf c,r) ϕsphere(p)=pc2r\phi_{\mathrm{sphere}}(\mathbf p)=\lVert\mathbf p-\mathbf c\rVert_2-r
Plane Unit normal and offset: (n,h)(\mathbf n,h) ϕplane(p)=nph\phi_{\mathrm{plane}}(\mathbf p)=\mathbf n\cdot\mathbf p-h
Axis-aligned box Center, half-sizes, and helper vector: (c, b=(bx,by,bz), q=pcb)(\mathbf c,\ \mathbf b=(b_x,b_y,b_z),\ \mathbf q=\lvert\mathbf p-\mathbf c\rvert-\mathbf b) ϕbox(p)=max(q,0)2+min(max(qx,qy,qz),0)\phi_{\mathrm{box}}(\mathbf p)=\lVert\max(\mathbf q,\mathbf 0)\rVert_2+\min(\max(q_x,q_y,q_z),0)

For the box, absolute value, maximum, and subtraction on bold vectors are componentwise. The first term handles exterior distance to the nearest face, edge, or corner; the second supplies the negative interior distance to the nearest face.

The information hidden in the field

The zero level set

p:ϕ(p)=0{\mathbf p:\phi(\mathbf p)=0}

is the visible surface, but neighboring level sets are useful too. When the level-set value is positive, ϕ=c\phi=c describes an outward offset by distance cc. Negative level sets describe inward offsets where they exist; near the medial axis, they can develop singularities, merge, or disappear.

Where the SDF is differentiable, it satisfies the eikonal equation

ϕ=1.|\nabla\phi|=1.

At smooth boundary points, the normalized gradient gives the outward surface normal:

n=ϕϕ.\mathbf n=\frac{\nabla\phi}{|\nabla\phi|}.

For an exact, differentiable SDF, the denominator is one. In numerical work it is usually retained because sampled, interpolated, composed, or learned fields are rarely exact.

An SDF is continuous, but it is not differentiable everywhere. If a point has more than one equally close boundary point, the direction to the surface is ambiguous. Inside the solid, such points lie on the medial axis; more generally they form part of the cut locus. The crease in the distance field is not a defect; it records the internal symmetry of the shape.

Building shapes with functions

Suppose ϕA\phi_A and ϕB\phi_B represent two solids using negative-inside SDFs. Familiar set operations have remarkably short formulas:

Operation Field formula
Union, ABA\cup B min(ϕA,ϕB)\min(\phi_A,\phi_B)
Intersection, ABA\cap B max(ϕA,ϕB)\max(\phi_A,\phi_B)
Difference, ABA\setminus B max(ϕA,ϕB)\max(\phi_A,-\phi_B)
Complement of AA ϕA-\phi_A

These rules make constructive solid geometry feel like scalar arithmetic. A sphere can be subtracted from a box, repeated, rounded, or blended without explicitly rebuilding a polygon mesh after every operation.

There is an important qualification. The min and max formulas preserve the correct inside/outside classification and zero boundary, and they provide useful distance bounds for sphere tracing. But the resulting field is not necessarily the exact Euclidean distance to the combined surface everywhere, particularly near intersections and internal seams. Smooth minimum functions can replace hard unions to create rounded blends, but they change both the geometry and the distance property. Reinitialization or a fresh distance computation may be required when exact distances matter.

Moving and scaling an SDF

SDF transformations are most naturally expressed by transforming the query point back into the shape’s local coordinate system.

Transformation New field
Translation by t\mathbf t ϕ(p)=ϕ(pt)\phi'(\mathbf p)=\phi(\mathbf p-\mathbf t)
Rotation RR ϕ(p)=ϕ(R1p)\phi'(\mathbf p)=\phi(R^{-1}\mathbf p)
Uniform scale s>0s>0 ϕ(p)=sϕ(p/s)\phi'(\mathbf p)=s\,\phi(\mathbf p/s)

Translation and rotation preserve distance because they are rigid motions. Uniform scaling requires multiplying the returned value by ss. Nonuniform scaling, twisting, bending, and other deformations are less convenient: a transformed implicit function can still have the correct zero set without remaining an exact SDF. Practical renderers often compensate with conservative distance bounds.

Sphere tracing: letting distance choose the step

One of the best-known uses of SDFs is sphere tracing, introduced by John C. Hart for rendering implicit surfaces. A camera ray can be written as

r(t)=o+td,\mathbf r(t)=\mathbf o+t\mathbf d,

where o\mathbf o is its origin and d\mathbf d is a unit direction. At a sampled point, the absolute SDF value is the radius of an empty sphere that cannot contain the surface. The ray can therefore advance by that amount without stepping through the first intersection.

t = 0
repeat:
p = origin + t * direction
step = abs(sceneSDF(p))
if step < tolerance: report a hit
t = t + step
until t exceeds the view limit or the step limit

Far from geometry, sphere tracing takes large steps through empty space. Near a surface, the steps shrink until they meet the chosen tolerance. It handles shapes that would be awkward to triangulate and scenes assembled from nested functional operations.

The guarantee depends on the field. A true distance function is safe, and a conservative signed distance bound can also be safe. An arbitrary implicit function—or an SDF distorted by an unsafe transformation—may overestimate clearance and cause the ray to skip through thin features.

Surfaces that move and change topology

Distance fields are also central to level set methods. Instead of explicitly moving mesh vertices, a surface is carried as the zero contour of a higher-dimensional scalar field. A common evolution equation is

ϕt+Fϕ=0,\frac{\partial\phi}{\partial t}+F|\nabla\phi|=0,

where FF is the speed of the interface in its normal direction. The speed can depend on curvature, position, material properties, an external flow, or image data.

This Eulerian description handles topological events naturally. Two expanding surfaces can merge, a neck can pinch apart, and a hole can appear without changing a mesh connectivity table. Osher and Sethian’s foundational work used Hamilton–Jacobi formulations to track fronts whose motion depends on curvature, with applications including crystal growth and flame propagation.

As the field evolves numerically, it may stop satisfying ϕ=1|\nabla\phi|=1. Many solvers therefore periodically reinitialize the field, restoring distance-like values while preserving the zero level set.

How distance fields are represented

An SDF is a continuous idea, but computers must choose a representation.

Representation Strength Limitation
Analytical function Compact, exact for supported primitives, resolution independent Complex shapes need many operations or special formulas
Dense grid Simple sampling and interpolation; works with arbitrary geometry Memory grows cubically with resolution in 3D
Narrow-band grid Stores detail only near the surface Long-range distance queries need special handling
Adaptive tree or sparse grid Concentrates samples where detail requires them More complex traversal and interpolation
Neural field Continuous learned representation; can encode shape families Evaluation and training cost; distance and sign may be approximate

Adaptively sampled distance fields, introduced by Frisken and colleagues, reduce storage by sampling the field finely near detailed regions and coarsely where it changes predictably. Sparse grid structures follow a similar principle for simulation and visual effects.

More recently, systems such as DeepSDF have used neural networks to approximate a continuous signed distance function. A network receives a 3D coordinate—often together with a latent code describing a particular object—and predicts the signed distance. This makes it possible to reconstruct incomplete shapes, interpolate between examples, and represent an entire learned class of geometry rather than one fixed object.

The word “SDF” should still be used carefully in learned systems. Unless distance constraints are enforced successfully, the network may reproduce the correct zero surface without satisfying the eikonal equation or returning accurate metric distance away from it.

Powerful, but not effortless

Signed distance fields exchange explicit topology for continuous queries. That trade is not always advantageous.

High-resolution 3D grids can consume enormous amounts of memory. Sampling and interpolation can erase small features or shift the zero crossing. Determining a reliable sign from an open, non-manifold, or self-intersecting mesh is difficult. Sharp corners create nondifferentiable regions, and Boolean operations or deformations can destroy exact distance behavior. Converting the result back to a mesh introduces another approximation through algorithms such as marching cubes or dual contouring.

The best implementation therefore depends on the task. A triangle mesh remains excellent for rasterization and explicit surface editing. An analytical SDF is ideal for compact procedural geometry. Sparse sampled fields work well for large, evolving volumes. Neural fields trade direct storage for learned inference. Many modern systems combine several representations rather than treating one as universal.

How Rig Cad combines SDF and mesh geometry

Rig Cad combines SDF and mesh geometry in a single modeling workflow. Use SDFs for organic forms, smooth blends, lattices, offsets, and other field-defined structures; use mesh-based operations where crisp, explicitly modeled features matter.

The multi-kernel showcase above demonstrates the central design idea: a scalar field can define the shape, while mesh conversion and conventional operations prepare it for downstream editing, visualization, and manufacturing. The goal is not to make one representation universal, but to move between representations without losing the strengths of either.

In the object tree, click the purple diamond on a Boolean to solve that branch as an SDF. Its descendants turn purple and use SDF options such as smooth blending. Set Precision on the root of the SDF branch; descendant precision values do not override it.

Enabling SDF mode on a Boolean node with the purple diamond
The purple diamond switches a Boolean branch to the SDF kernel.

Next steps

Continue with Gyroid TPMS: When Geometry Becomes Structure, which develops an implicit level-set equation into a tunable engineering and decorative surface.

Within Rig Cad, apply the same field principles when choosing smooth operations, precision, mesh conversion, and extraction settings. Keep field-defined construction separate from later result-level processing and final mesh validation.