Ray tracing: rendering by running light backward
In Pixar movies, and in video games with 'RTX' reflections and shadows
What problem does it solve?
How do you compute what a camera would see in a 3D world of shapes, lights and mirrors?
The big idea
Real light pours from lamps and only a tiny fraction ever reaches your eye. So the computer runs it backward: from the eye, shoot one ray through each pixel and ask 'what does this hit first?'. That question is just algebra: hitting a sphere means solving a quadratic equation, where no real solution means you missed. From the hit point, shoot more rays toward lights (shadows), in the mirror direction (reflections) and in random directions (soft bounced light). Averaging many random bounces gives 'path tracing', the near-photographic method modern films use.
How it works, step by step
- 1. For each pixel, make a ray from the camera through that pixel: point = o + t·d.
- 2. Find the nearest object the ray hits (for a sphere, solve a quadratic for t).
- 3. At the hit point, shoot a ray toward each light; if something blocks it, the point is in shadow.
- 4. For shiny or glassy surfaces, shoot reflected or refracted rays and add their colour.
- 5. Path tracing: bounce in random directions many times per pixel and average (Monte Carlo).
The key formula
- where the ray starts (the camera)
- the ray's direction through the pixel
- how far along the ray: the unknown, found with the quadratic formula
- the sphere's centre and radius
How fast is it?
Very expensive: millions of pixels × many rays per pixel × many bounces. Film frames can take hours each on big render farms. Games manage it in real time with special ray-tracing hardware (NVIDIA RTX GPUs, since 2018), few rays per pixel, and AI 'denoisers' that clean up the speckled result.
Try it yourself
- Solve for t when a ray from (0,0,0) along direction (0,0,1) hits a sphere of radius 1 centred at (0,0,5). (t = 4 and t = 6: entering and leaving.)
- Why does a picture with only 1 random ray per pixel look speckled? (Monte Carlo noise, which shrinks like 1/√N.)
Fun fact
Turner Whitted published the classic recursive ray-tracing method in 1980, and Jim Kajiya wrote down the 'rendering equation' behind path tracing in 1986. Pixar's Cars (2006) was the first Pixar film to use ray tracing extensively, for those shiny car reflections.