Computer Graphics · Geometry Representation

Signed Distance Fields as an Implicit Surface

How a function of position replaces a mesh, why the gradient gives the normal, how min and max build constructive solid geometry, and what storage a sampled field needs.

A mesh answers one question: given a point, is it inside. A signed distance field answers that question as a function $f: \mathbb{R}^3 \to \mathbb{R}$, where $f(x)$ is the Euclidean distance from $x$ to the nearest point on the surface, positive outside and negative inside. The surface itself is the zero set $f(x) = 0$. Nothing about the surface is stored as connectivity; the geometry is the level set of a scalar function, and that change of representation buys and costs a great deal.

What the sign buys

An unsigned distance field cannot distinguish a point one centimetre inside a wall from one centimetre outside it, and that distinction is most of what geometry code needs. With the sign available, the inside test is f(x) < 0, a single comparison, and it costs the same regardless of the surface’s complexity. An intersection of two objects is max(fA, fB); a union is min(fA, fB); a difference is max(fA, -fB). Each is one instruction per evaluation point, and the resulting shape has exact topology because the boolean was performed on the functions rather than on the surfaces.

For a mesh, the equivalent operation requires intersecting every triangle pair, cutting both surfaces along the intersection curves, classifying the resulting pieces, and stitching the boundary. That procedure is described under robust mesh booleans and is one of the hardest operations in geometry processing. The field formulation replaces it with a min, at the cost of losing the ability to represent a sharp edge exactly: min(fA, fB) of two smooth fields produces a crease whose exact location is only where the two fields are equal, and near the crease the field is not a true distance field at all. Its gradient magnitude drops below one.

That last point is the field representation’s central defect. The distance function satisfies the eikonal equation $|\nabla f| = 1$ almost everywhere, but the min and max of two exact distance fields generally do not. A field that violates it by a small margin still defines the right surface, but every algorithm that assumes unit gradient, including the ray marching method below, must be given a conservative estimate rather than the raw value.

The gradient is the normal, and second derivatives are curvature

For a true signed distance field, the gradient $\nabla f$ at any point off the surface is the unit direction from that point to the closest surface point. On the surface, it is the outward unit normal. The normal is therefore a finite difference away, at no storage cost: sample the field at $x \pm h$ along each axis, and the central difference gives the direction. Step size matters; too large and creases are rounded, too small and floating-point cancellation dominates. With single-precision floats and coordinates of magnitude around one, a step near $10^{-3}$ keeps the difference well above the noise floor.

The Laplacian of the field gives mean curvature, and the eigenvalues of the Hessian give principal curvatures, so a field carries differential properties that a mesh only approximates through its discrete connectivity. A mesh’s per-vertex normals are an average of face normals and their accuracy depends on triangulation quality; the field’s gradient is exact up to the sampling used to evaluate it.

The offset surface is also free: the set $f(x) = d$ is the surface offset outward by $d$. For a mesh this operation is genuinely difficult, because offset triangles overlap near concave regions and must be trimmed. The field has no such problem until $d$ exceeds the local radius of curvature, at which point the offset self-intersects and the field develops a medial-axis structure that the level set cannot resolve.

Sphere tracing and the step size that is safe

Rendering an implicit surface by ray casting rests on one property: for a true distance field, a ray travelling from point $p$ along unit direction $d$ cannot hit the surface within distance $f(p)$. So a sphere of radius $f(p)$ around $p$ is empty, and the ray can advance by exactly that amount with no risk of tunnelling. Repeat until $f$ falls below a tolerance.

/* d() returns a conservative distance bound for the scene at p */
static float d(const float p[3]);

float trace(const float ro[3], const float rd[3], float tmax) {
    float t = 0.0f;
    for (int i = 0; i < 256; i++) {
        float p[3] = { ro[0] + rd[0] * t, ro[1] + rd[1] * t, ro[2] + rd[2] * t };
        float dist = d(p);
        if (dist < 1e-4f) return t;                   /* converged */
        t += dist * 0.9f;                             /* undershoot for safety */
        if (t > tmax) break;
    }
    return -1.0f;                                     /* no hit */
}

The $0.9$ factor compensates for fields that are not exact distances. With an exact field the full step is safe and the iteration count is logarithmic in the distance to the surface divided by the tolerance. With a badly scaled field, say one that returns half the true distance, the full step is still safe but converges at half speed, which is why under-estimating is the conservative direction and over-estimating produces visible artifacts where rays pass through thin geometry.

The classic failure is grazing rays that run nearly parallel to the surface. Each step is small because the distance to the surface is small, and the convergence is slow: a ray at one degree of incidence needs many iterations to travel a long distance. Silhouette regions therefore dominate the cost, and the artifact of hitting the iteration cap is a missing pixel at the object’s edge.

Sampling, storage, and filtering

Analytic fields are cheap in memory and expensive in evaluation. A procedurally defined field costs a few dozen instructions per sample, which is fine for a handful of rays but prohibitive for the millions of samples a rasterizer needs. The alternative is to bake the field into a voxel grid and trilinearly interpolate.

A grid of $N^3$ samples at 32-bit float is $4N^3$ bytes. At $N = 128$ that is 8 MiB; at $N = 256$ it is 64 MiB. Resolution is set by the finest feature that must survive, and a rule of thumb from the field’s own definition is that a feature of size $h$ needs sample spacing well below $h$. This is why three-dimensional fields at production resolution are stored sparsely, keeping only cells near the surface, and often quantized to 16 bits or 8 bits with a per-block scale. An 8-bit quantization of a field normalized to $[-1, 1]$ has a step of about $0.0078$, which bounds the surface position error to roughly that value; the interpolation smooths the steps into a slope error rather than a positional one.

Trilinear interpolation of a sampled field does not preserve the distance property. Along a cell diagonal the interpolated value can exceed the true distance, so a ray marcher using the interpolated value at full step can skip through a thin feature. The standard defences are to scale the step down, to compute a conservative bound from the local cell’s gradient magnitude, or to use a tetrahedral interpolation whose error is easier to bound.

Where fields lose to meshes

A field cannot represent a hard crease exactly, cannot represent an open surface with a boundary, and imposes a uniform sampling cost regardless of local detail. Its memory scales with volume, while a mesh’s scales with surface area: doubling the resolution of a mesh representation of a sphere quadruples its triangle count, while doubling the grid resolution of a field multiplies storage by eight. For thin or sheet-like geometry such as fabric, foliage, or a car panel, the field wastes almost all of its samples in empty space, and the mesh wins decisively.

Fields also compose badly with animation that moves topology. Skinning a mesh is a per-vertex matrix blend applied at load; skinning a field means either re-baking it per frame or transforming the query point into the rest pose, which works only if the deformation is invertible and the field’s distance property survives the Jacobian of the deformation. A non-uniform scale changes distances, so the warped field is no longer a distance field and step sizes must be adjusted by the local scale factor.

The niche where fields dominate is the one where exact topology and cheap booleans matter more than surface fidelity: shape blending, procedural modelling, collision queries against deforming objects, and text rendering, where a two-dimensional field sampled at moderate resolution gives antialiased glyph edges at any scale from a single texture. Extracting a mesh from such a field is a separate problem, solved by marching cubes and its ambiguity cases.

References

  1. Sphere Tracing: A Geometric Method for the Antialiased Ray Tracing of Implicit Surfaces — John C. Hart, The Visual Computer, 1996
  2. Implicit Objects in Computer Graphics — Velho, de Figueiredo, Gomes, Springer
  3. Improved Alpha-Tested Magnification for Vector Textures and Special Effects — Chris Green, SIGGRAPH 2007