SDFs in Game Development: Collision, AI, Shadows, and Terrain

EN NL ES PT-BR


Signed distance fields (SDFs) are not just a rendering technique. In game development, the same compact scalar function that drives ray-marched visuals also solves collision queries, steers AI agents, softens shadows, and deforms terrain in real time. Each of those applications is a discipline of its own with its own query patterns, code, and performance tradeoffs, so this page introduces all five.

If you need a refresher on the fundamentals (how sign and magnitude work, what CSG operations do, or how sphere tracing steps through a field), start with the Signed Distance Fields overview .

How SDFs Fit Game Engines

A game engine spends most of its frame budget on a handful of spatial questions. Is this bullet inside that collision volume? How far is this character from the nearest wall? What direction should this particle bounce? Which shadowed pixels should this light skip?

Every one of those questions can be answered by evaluating an SDF at the right point. The SDF gives you distance and side in one query. That is the core reason SDFs show up across so many engine subsystems: the representation stays the same, and only the query pattern changes.

This is fundamentally different from mesh-based workflows. A triangle mesh stores surface locations but cannot answer “how far am I from the nearest surface?” without an expensive closest-point search. A bounding volume hierarchy accelerates that search but still requires traversing a tree structure. An SDF answers the same question in constant time per evaluation point. That difference compounds when you need to query hundreds or thousands of points per frame for physics contacts, shadow rays, or navigation samples.

The tradeoff, as always, is representation cost. Analytical SDFs are exact but limited to shapes you can describe with a formula. Sampled SDFs can represent any geometry but consume memory proportional to grid resolution and introduce interpolation error. Game engines typically use a mix: analytical SDFs for procedural and simple-collider shapes, sampled SDFs for complex static meshes, and traditional triangle data for everything else.

The Five Game-Dev Applications

The five sections below cover the main game-dev applications of SDFs: collision detection, physics and particle systems, AI pathfinding and navigation, real-time shadows and ambient occlusion, and destructible terrain. Each section links to a dedicated page that goes into the details.

Collision Detection

Collision detection is the most natural game-dev application of SDFs. The sign of the field tells you immediately whether a point is inside, outside, or on a surface, which turns point-in-volume tests into a single arithmetic check. The magnitude provides penetration depth and the gradient provides the separation direction, the two values a physics solver needs to push overlapping objects apart. And because the field never overestimates distance, sphere casting along motion vectors provides continuous collision detection with the same safe-step guarantee as sphere tracing, so fast projectiles do not tunnel through thin walls.

The SDF collision detection page covers point-in-volume queries, penetration depth computation, vertex sampling strategies, sphere casting, and the performance comparison against bounding volume hierarchies.

Physics and Particle Systems

Particle systems and soft-body interactions are where per-particle queries against complex implicit surfaces would be prohibitively expensive with mesh-based methods. Each particle needs only a distance evaluation and a gradient evaluation to detect penetration, project back to the surface, and reflect velocity with a configurable bounce. The same gradient drives continuous repulsion forces that make particles slide along soft boundaries instead of bouncing off hard ones. The pattern scales to millions of particles because there is no acceleration structure to traverse.

The SDF physics and particle systems page walks through collision response, force fields, and the connection to level-set fluid simulation.

AI Pathfinding and Navigation

Game AI constantly asks spatial questions: where is the nearest cover, how much clearance does this spot offer, and which direction keeps a unit at a preferred distance from a wall? An environmental distance field answers all of them with field evaluations. Its values encode clearance, and its gradient points toward the nearest obstacle, which makes wall-following and obstacle avoidance natural steering forces. For crowds, the same machinery builds flow fields that route hundreds of agents with a single global vector field.

The SDF AI pathfinding and navigation page covers clearance queries, gradient-based steering, flow fields, and how distance-field navigation compares with traditional navmeshes.

Real-Time Shadows and Ambient Occlusion

Shadow maps struggle with soft penumbra and alias at shallow angles. An SDF of the scene produces soft shadows by marching a secondary ray toward the light and recording how closely the ray grazes occluding geometry, which estimates penumbra width without extra shadow map passes or cascades. Ambient occlusion works the same way: sample the field in a hemisphere around a surface point and accumulate occlusion wherever the field goes negative, producing contact shadows in crevices and under overhangs.

The SDF soft shadows and ambient occlusion page explains the penumbra math, the occlusion sampling scheme, and when SDF lighting beats shadow maps.

Destructible Terrain and Real-Time Deformation

Destructible environments are one of the hardest problems in game rendering because a mesh must be re-triangulated whenever the surface changes. With an SDF, carving a crater is a single CSG subtraction: max(terrain, -crater) removes exactly the volume where the explosion happened. The SDF tree grows by one primitive per deformation with no mesh topology to maintain, and Marching Cubes extracts a fresh triangle mesh for rasterization each frame.

The SDF destructible terrain page covers CSG carving, mesh extraction, and hybrid heightfield approaches.

When to Use SDFs in a Game

Triangle meshes and SDFs are complementary representations that win in different scenarios. Understanding those boundaries prevents over-engineering.

Scenarios Where SDFs Excel

Procedural and deformable geometry. When shapes are generated at runtime or change every frame, the cost of maintaining a mesh representation outweighs the cost of evaluating an SDF. Procedural planets and destructible terrain benefit from an implicit representation, as covered on the destructible terrain page.

CSG-heavy level construction. A level built from hundreds of boolean operations on primitives is natural as an SDF and painful as a mesh. The SDF CSG tree is compact and always watertight; the equivalent mesh boolean operations produce degenerate triangles, floating-point cracks, and non-manifold edges.

Many-to-one collision queries. When hundreds of projectiles, particles, or AI agents need distance information against the same static environment, pre-baking an environmental distance field and querying it per entity is dramatically faster than per-entity mesh traversal. The collision detection page works through the numbers.

Soft shadows and ambient occlusion without pre-computation. SDF-based shadow and AO techniques produce smooth results with no shadow map cascades, no bake times, and automatic handling of dynamic geometry, as detailed on the shadows and AO page.

Scenarios Where Meshes Excel

Artist-authored hero assets. Character models, weapons, and set-piece environment props are built by artists in modeling tools with careful topology, UV maps, and material assignments. Converting these to SDFs discards the UV data and topology details that make them look polished.

Hardware-accelerated rasterization. GPU triangle rasterization is one of the most optimized pipelines in computing. For a static scene with millions of triangles, rasterization with shadow maps is significantly faster than sphere tracing an equivalent SDF, because fixed-function hardware handles the depth-testing and attribute interpolation.

High-frequency surface detail. Normal maps, displacement maps, and texture-based detail are the standard way to add surface complexity without adding geometry. SDFs can incorporate displacement, but the cost scales with the detail frequency because the SDF must be evaluated at tighter spacing to resolve fine features.

Animation and skinning. Skeletal animation deforms a mesh by transforming its vertices with bone weights. An SDF has no vertices to transform; you would need to deform the SDF’s coordinate space, which works for rigid transforms but not for the smooth, non-uniform deformation of skinned characters.

A Practical Integration Strategy

Most engines that use SDFs treat them as one tool among several. A common pattern:

  1. Bake environmental distance fields for static level geometry at build time. Use them for NPC pathfinding, dynamic object collision queries, and real-time soft shadows.
  2. Represent destructible surfaces as analytical SDF trees with CSG operations. Extract meshes with Marching Cubes for rasterization.
  3. Keep hero assets and characters as traditional triangle meshes with skeletal animation and PBR materials.
  4. Use SDF-based soft shadows and ambient occlusion as a supplemental pass on SDF-represented geometry, not as a replacement for the primary shadow pipeline.

This hybrid approach gets the benefits of both representations without trying to force one to solve every problem.

Summary

SDFs are a workhorse representation in game development because they answer the spatial questions that engines ask most often. The same SDF that describes a shape for rendering also feeds collision queries, steers AI agents, softens shadows, and absorbs deformation events.

The representation is not universal. Triangle meshes remain better for hero assets, skinned characters, and high-throughput rasterization. But for the spatial query workloads that dominate physics, AI, and dynamic environment systems, SDFs turn what would be search problems into evaluation problems, and that transformation is what makes them indispensable in modern game engines.