← COURSE LIBRARY
Procedural · 60 min

Signed Distance Fields and Ray Marching

AdvancedNeeds: VectorsNeeds: Smoothstep
Sign in to record mastery, quiz results and reviews for this course.Sign in

You will be able to

  • Write distance functions for basic primitives and combine them with booleans.
  • Implement sphere tracing with a sane step and epsilon budget.
  • Explain why SDF cost is view-dependent and how to bound it.

The concept

An SDF returns the signed distance to the nearest surface, which lets you march a ray by exactly that distance without overshooting. Booleans become min/max, and smooth booleans become polynomial blends. The cost model is unusual: grazing rays that skim a surface take many small steps, so worst-case cost is driven by silhouettes, not by geometry count.

In your engine

Full-screen raymarch in a fragment shader with the camera ray reconstructed from clip space.

Practice (4)

Complete the code
Write the SDF of a sphere of radius r centred at the origin, given point p.
Predict the result
Combining two SDFs with max(a, b) produces:
Find the bug
Your march produces banded artefacts on curved silhouettes. Which change is the correct first fix?
Tune the value
A smooth union uses a blend radius k. Setting k to 0 gives a result equivalent to which operation? Enter 0 for min-union or 1 for intersection.

Knowledge check

01Sphere tracing steps by:
02SDF normals are usually obtained by:
03Worst-case ray march cost is driven by:
04Subtraction of B from A is:

Build challenge

Ray-march a shape built from at least three primitives with one smooth union, staying under 64 steps at 1080p. Profile it and report the cost delta between a head-on and a grazing camera angle.

SELF-CHECK RUBRIC

Your mastery state

Apply it in a guided project