Signed Distance Functions
There's a mathematical idea from the late 1980s that quietly became one of the most versatile primitives in computer graphics. A signed distance function (SDF) takes a point in space and returns the distance to the nearest surface — positive if you're outside, negative if you're inside. That's it. From this single concept, you can build ray marchers, construct complex scenes through boolean operations, model volumetric clouds, light entire game worlds, and render a rotating donut on a chip with no memory and no multiplications.
The Idea
John Hart's 1989 paper on ray tracing deterministic 3D fractals introduced sphere tracing: if you know how far away the nearest surface is, you can safely step that distance along a ray without missing anything.1 March forward, query the distance again, step again. When the distance drops below some epsilon, you've hit something. It's not exact — you get an approximation — but it's fast and it works for any geometry you can describe as a distance function.
The beauty is in composition. Want a sphere? length(p) - radius. A box? Take the max of the distances along each axis. A torus? Two sequential 2D length operations — find the distance to a ring, then find the distance to the surface of the tube around that ring.2 These are your atoms. The molecules come from combining them: the minimum of two SDFs gives you their union, the maximum gives you their intersection, and negating an SDF carves space out of the world. Smooth minimum blends shapes together organically, turning separate spheres into blobby metaballs.3
This is constructive solid geometry (CSG), but without meshes, without vertices, without any of the data structures that dominate conventional 3D graphics. The entire scene lives in a function. Inigo Quilez, who did more than anyone to popularize SDFs through Shadertoy and his encyclopedic website, demonstrated that you can build staggeringly complex scenes this way — his "Snail" and "Surfer Boy" shaders generate photorealistic geometry entirely from mathematical expressions, with infinite resolution at any zoom level.4
Ray Marching in Practice
The standard ray marching loop is almost trivially simple. For each pixel, construct a ray from the camera. Start at the near plane. Query the SDF. Step forward by the returned distance. Repeat until you either get close enough to declare a hit or exceed some maximum distance. When you hit, compute the surface normal by taking finite differences of the SDF — nudge the point slightly in x, y, and z, query again, and the gradient points away from the surface.5
This simplicity is what makes SDFs so attractive for creative coding. You don't need a mesh loader, a triangle rasterizer, or an acceleration structure. A complete ray marcher fits in a fragment or compute shader. The Shadertoy community has turned this into an art form: thousands of shaders that generate entire worlds — landscapes, creatures, architecture — from nothing but math and a distance function.
Adding volumetric effects is just as natural. Instead of marching until you hit a hard surface, you can sample density along the ray, accumulating opacity and color. Chris Wallis demonstrated this by building volumetric clouds in Shadertoy from SDFs distorted with fractal Brownian motion noise — take a smooth union of a few spheres, warp the surface with fBM, and suddenly you have something that looks like a thunderhead.3 The SDF gives you the broad shape; the noise gives you the detail. Time-varying the noise index produces rolling fog that looks genuinely atmospheric.
SDFs in Production
What's remarkable is that SDFs jumped from the demoscene and hobby graphics into AAA production. Unreal Engine 5's Lumen global illumination system traces rays not against triangles but against a scene representation built from signed distance fields, voxels, and height fields.6 The hierarchy is elegant: screen-space traces handle fine detail, mesh SDFs handle medium-scale light transfer, and voxel traces handle large-scale bounced lighting. This lets Lumen deliver fully dynamic global illumination without hardware ray tracing — it runs on the PlayStation 5 without requiring RT cores.
Brian Karis explained that Nanite, UE5's micro-polygon system, enables this by rendering into virtualised shadow maps so efficiently that they can afford effectively 16K shadow maps per light, compared to the 2K of previous generations.6 The SDFs aren't just a curiosity here — they're load-bearing infrastructure for one of the most important rendering engines in the industry.
The Implicit Surface Revival
Jasper St. Pierre wrote a fascinating history of why 2D vector graphics are harder than 3D, and in it traced the divergence between implicit curves (which dominate 2D, thanks to PostScript's Bezier-based imaging model) and polygonal meshes (which won the 3D war through sheer practicality).4 SDFs represent a return of implicit surfaces — the same approach that MAGI used to render the lightcycle sequences in Tron back in 1982, before triangles bulldozed everything else.
The difference is that in 1982, artists had to compose spheres and cylinders to approximate complex shapes. Today, with smooth boolean operations, noise displacement, and domain repetition, SDFs can represent organic geometry that would require millions of triangles. MediaMolecule's Dreams on PS4 was built entirely around SDF sculpting, reinventing most of traditional graphics in the process.
The tooling gap remains the biggest obstacle. Only someone with deep mathematical intuition can build Quilez's "Surfer Boy" in code. There's no Maya or Blender for SDFs — it's all equations. Dreams and Oculus Medium showed that intuitive SDF sculpting tools are possible, but they haven't displaced mesh-based workflows in the broader industry. Whether SDFs will eventually replace triangles or remain a complementary technique probably depends more on tooling than on any technical limitation.
SDFs Without Multiplication
Perhaps the most surprising application comes from Andy Sloane (a1k0n), who realised that the torus SDF — two sequential 2D length computations — could be evaluated using only shifts and adds via CORDIC.2 No multiplications, no trig functions, no square roots. He submitted a design to Tiny Tapeout 8 that ray-marches a rotating donut on a 130nm chip using about 7000 standard cells, racing the VGA beam with no frame buffer. The polygonal appearance from limiting CORDIC iterations to 3 was a happy accident — proof that tight constraints produce unexpected aesthetics.
The trick gets better: the CORDIC rotation that computes the distance also rotates an auxiliary lighting vector as a side effect, giving you the surface normal dot product (and thus diffuse lighting) for free. It's the kind of insight that only emerges when you're forced to think about computation at the gate level rather than the API level.
Voxels and Sparse Octrees
SDFs don't have to be analytical functions. Discretise the distance field onto a 3D grid and you get a voxel SDF — each cell stores its distance to the nearest surface, and the zero-level isosurface can be extracted or ray-marched directly. The practical question is storage: a naive grid at useful resolution is enormous. Sparse voxel octrees (SVOs) solve this by only subdividing space where geometry actually exists, storing "bricks" of voxels at leaf nodes and empty markers elsewhere.7
John Whigham's SVO experiments showed that ray casting against octrees combines the benefits of implicit surfaces (infinite-resolution feel, clean boolean operations) with the benefits of discrete data (artist-editable, detail where you want it). The octree traversal finds the right level of detail, then ray-marches through a brick of 8x8x8 voxels to find the precise intersection. The surface normal comes from the gradient of the stored distance values, and interpolating between voxels produces smooth rather than blocky geometry — even at coarse resolution, a 16x16x16 brick can approximate surprisingly organic shapes.7
Doug Binks pushed this further by implementing a full path tracer against a sparse voxel octree DAG (directed acyclic graph, which deduplicates identical subtrees for a ~4x memory savings) on the GPU.8 The conversion from C++ to GLSL shader code surfaced the kind of details that matter in practice: std140 vs std430 buffer layout broke the octree indexing, and the difference between sign(0.0) returning 0 and copysign(1.0, 0.0) returning 1 caused rays to miss surfaces. He debugged this by dreaming the answer overnight — literally — which may be the most demoscene debugging story ever told.
The connection to GPU pipeline architecture is worth noting: voxel path tracing is naturally divergent (every ray hits different octree nodes at different depths), which fights the warp-level uniformity that GPUs want. But the octree structure itself helps — nearby rays tend to traverse similar nodes, and the hierarchical structure lets you skip empty space efficiently. The debug visualization of nodes-traversed-per-ray shows bright halos around surfaces where the octree is densely subdivided, and dark areas in open space where rays sail through at the coarsest level.
What SDFs Actually Are
Strip away the applications and SDFs are a way of encoding geometry as a scalar field — every point in space gets a number. This is the same mathematical structure as a potential field in physics, a level set in computational geometry, or a loss landscape in machine learning. The zero-level set is your surface. Everything else is context: how fast the field changes tells you about curvature, the gradient tells you surface orientation, and the field values themselves tell you how much room you have to step.
This generality is why SDFs keep showing up in unexpected places. They're a natural fit for collision detection, font rendering (multichannel SDF textures are the standard approach for resolution-independent text), physics simulation, and increasingly, neural implicit representations like NeRFs and their descendants. The humble distance query — "how far am I from the nearest surface?" — turns out to be one of the most useful questions you can ask about geometry.
Footnotes
-
Ray Tracing Deterministic 3-D Fractals by John Hart et al. — source ↩
-
From ASCII to ASIC: Porting donut.c to a tiny slice of silicon by Andy Sloane — source ↩ ↩2
-
Why are 2D vector graphics so much harder than 3D? by Jasper St. Pierre — source ↩ ↩2
-
Inside Unreal Engine 5 by Alex Battaglia / Digital Foundry — source ↩ ↩2
-
Sparse Voxel Octrees: A New Beginning by John Whigham — source ↩ ↩2
-
Implementing a GPU Voxel Octree Path Tracer by Doug Binks — source ↩
Linked from
- 2D Vector Graphics On Gpu
This is why SDF techniques spread so quickly — the shader is trivial and the results look great.
- 2D Vector Graphics On Gpu
Meanwhile, the demoscene has been rendering implicit curves and signed distance functions on GPUs for years, demonstrating that the hardware can handle non-triangular geometry when you're creative enough.
- Demoscene
The scene is defined entirely through signed distance functions — no vertices, no meshes.
- Demoscene
The whole thing is a single expression — a distance function composed with domain repetition (mod operations that tile the space infinitely), evaluated through ray marching, with lighting from the march steps themselves.
- Demoscene
So the demoscene, which grew up on hardware designed for triangles, had to rediscover implicit surfaces — signed distance functions, ray marching, boolean composition — because they couldn't afford the triangle budgets that mainstream games used.
- Demoscene
When you can't afford a triangle rasteriser, you invent ray marching with SDFs.
- Graphics And Rendering Overview
Signed Distance Functions is where the implicit story starts.
- Path Tracing
*Ray marching* replaces the hit test with iterative stepping, typically using signed distance functions to determine safe step sizes.
- Path Tracing
Andrew Kensler's postcard-sized path tracer packs many of these ideas into 2037 bytes of C++: cosine-weighted hemisphere sampling for diffuse bounces, direct light evaluation with shadow rays, Reinhard tone mapping, and a complete SDF-based scene — a…
- Procedural Terrain Generation
The distance transform output is directly usable as a signed distance field texture — the "next best thing to vector graphics" for scalable fonts and decals in games.
- Programming Languages Overview
The demoscene connection is worth noting: Shadertoy is the accidental realization of Victor's principle for graphics programming, providing immediate feedback that drove the development of SDF techniques that eventually entered production engines.
- Shader Programming
This directness is why so many SDF techniques were developed and refined there — the overhead of traditional graphics APIs would have killed the experimental momentum.
- Shader Programming
A variable-step ray marcher is elegant in SIMT but devolves into complex active-mask-tracking code in a tensor framework.
- Shader Programming
The signed distance functions community showed that you could render without meshes by marching through scalar fields.
- Volumetric Rendering
The trick used by Chris Wallis and others in ShaderToy volumetrics is to model the volume using Signed Distance Functions with fBM noise distortion. Start with a few smooth-unioned spheres for the basic shape, then add fractal Brownian motion noise i…