Ray Tracing in One Weekend
A hands-on C++ tutorial for building a compact but capable path tracer from scratch: rays, geometry, Monte Carlo sampling, materials, camera control, and depth of field. It prioritizes clear baseline implementations that produce visually rich renders and can be extended into a fuller renderer.
Ray Tracing in One Weekend
Author: Peter Shirley, Trevor David Black, Steve Hollasch | Published: 2025-04-25 | Generated: 2026-03-07 | Domain: raytracing.github.io
Tags: ‘#raytracing’ ‘#pathtracing’ ‘#cpp’ ‘#computergraphics’ ‘#rendering’ ‘#montecarlo’
TLDR
This introductory book builds a CPU path tracer step by step, using C++ but emphasizing rendering concepts that transfer to other languages. It progresses from PPM image output and vector math to ray/object intersections, recursive Monte Carlo light transport, diffuse/metal/glass materials, antialiasing, configurable cameras, and defocus blur. The result is intentionally simple rather than production-ready, but its architecture provides a solid base for features such as BVHs, textures, lights, transforms, and volumetrics.
Key Takeaways
- Incremental renderer construction: The tutorial starts with plain-text PPM output, then adds
vec3, rays, sphere intersections, surface normals, ahittableabstraction, and a camera class to create an extensible rendering core. - Path-tracing fundamentals: Per-pixel random sampling reduces aliasing, while recursively scattered rays approximate indirect lighting;
samples_per_pixelcontrols sampling quality andmax_depthcaps bounce recursion. - Numerical robustness matters: The implementation uses hit intervals, ignores intersections below
t = 0.001to prevent shadow acne, rejects near-zero random vectors, clamps final intensities, and applies gamma-2 correction via square root. - Material models: Lambertian materials scatter around the normal and attenuate by albedo; metals use vector reflection plus optional fuzz in the
0–1range; dielectrics use Snell’s law, total internal reflection, and Schlick’s reflectance approximation. - Final reference scene: The cover-style render uses a 1200-pixel-wide image, 500 samples per pixel, a maximum depth of 50, hundreds of randomized small spheres, a 20° vertical FOV, and a
0.6°defocus angle. The repository’s development sample reduces samples per pixel to 10 for practical iteration time.
Images & Media
- Camera geometry — Shows the camera center, viewport, focal length, and right-handed viewing setup.
- Ray-sphere intersection results — Illustrates the zero, one, or two roots produced by the quadratic ray-sphere intersection test.
- Lambertian random-vector geometry — Explains generating diffuse scatter directions by adding a random unit vector to a surface normal.
- Refraction geometry — Visualizes the normal, incident ray, refracted ray, and quantities used in Snell’s law.
- Final rendered scene — The completed randomized-sphere path-traced image.
Referenced Links
- RayTracing project on GitHub — Finished source code, project structure, builds, releases, and contribution information.
- Graphics Codex — Recommended resource for learning or reviewing vector mathematics and graphics foundations.
- Further Reading wiki page — Additional project-related rendering resources.
- GitHub Discussions forum — Community support, implementation questions, and project discussion.
- A Pixel is Not a Little Square — Further reading on pixel sampling and reconstruction.
- stb — Header-only image-library collection suggested for output formats beyond PPM.