Here is where it all comes together. We can intersect a ray with a sphere, we can
That single self-referential rule produces hard shadows, mirror reflections, and clear glass almost for free — phenomena that older rasterizers had to fake with separate hacks. Whitted's 1980 algorithm is barely a page of pseudocode; let's derive it line by line.
Step 1 — shoot a primary ray per pixel. Place the camera at a point and the
image as a grid in front of it. For each pixel, fire one primary ray from
the camera through that pixel out into the scene. An image
Step 2 — find the nearest hit. Test the ray against every object and keep the
closest intersection (smallest positive distance
Step 3 — compute local lighting at the hit. At the hit point, evaluate the ambient + diffuse + specular colour from the previous page, using the surface normal there. This is the base colour of the surface before any reflections or shadows are folded in.
Step 4 — cast a shadow ray to each light. Is this point actually lit, or is something in the way? Fire a shadow ray from the hit point straight toward each light. If any object blocks it before the light, that light is occluded — drop its diffuse and specular contribution, and the point falls into shadow. Shadows are just "can the light see this point?", asked with one more ray.
Step 5 — recurse for mirror reflections. If the surface is reflective, spawn a reflection ray in the bounced direction
and call the same routine on it. Whatever colour that ray returns is what the mirror shows. This is the recursion: a mirror's pixel is coloured by re-running the whole tracer down the reflected ray.
Step 6 — recurse for transparency. If the surface is transparent, spawn a refraction ray bent by Snell's law into the material, and recurse on that too. Its returned colour is what you see through the glass. (Total internal reflection is handled here automatically — when refraction is impossible, the ray reflects instead.)
Step 7 — blend the returned colours by material. Combine the local shading with the reflected and refracted results, weighted by how mirror-like and how transparent the surface is:
where
Step 8 — stop at a maximum depth. Reflections inside reflections could
bounce forever (two facing mirrors), so cap the recursion at a maximum depth
That's the entire algorithm: trace, find the nearest hit, shade it, then trace the rays it spawns until you run out of depth. Shadows, mirrors, and glass all emerge from the same eight steps.
Raytracing has always been the beautiful, slow way to render. Its cost is brutal:
Two things changed it. Hardware gained dedicated RT cores that do ray–triangle intersection in silicon, and — crucially — denoising let renderers fire just a few noisy rays per pixel and reconstruct a clean image with a neural filter, instead of averaging thousands. Together they dragged the billion-ray frame into the millisecond budget of a game, and real-time raytraced reflections and shadows arrived in living rooms. The maths didn't change — these are still the same eight steps — we just learned to afford them.