Path Tracer
A physically-based renderer built in C++ following "Ray Tracing in One Weekend" by Peter Shirley, Trevor David Black, and Steve Hollasch.
A path tracer built from scratch in C++, following the “Ray Tracing in One Weekend” book series by Peter Shirley, Trevor David Black, and Steve Hollasch. The renderer simulates how light interacts with objects to produce photorealistic images.
How It Works
Path tracing is a rendering technique that simulates the physical behavior of light. For each pixel, rays are cast from a virtual camera into the scene. When a ray hits a surface, it bounces according to the material properties — diffuse surfaces scatter light randomly, metals reflect it, and dielectrics (like glass) both reflect and refract.
By tracing many rays per pixel and averaging the results, the renderer converges on a realistic image complete with soft shadows, color bleeding, and realistic reflections.
Technical Implementation
Ray-Sphere Intersection
The core of the renderer is solving the ray-sphere intersection equation. Each ray is tested against every object in the scene, and the closest hit determines the pixel color.
Materials
Three material types are implemented:
- Lambertian (Diffuse) — scatters light randomly for matte surfaces
- Metal — reflects rays with optional fuzziness for brushed metal effects
- Dielectric — handles refraction and reflection using Schlick’s approximation for materials like glass and water
Anti-Aliasing
Multiple rays are cast per pixel with slight random offsets, and the results are averaged. This eliminates harsh jagged edges and produces smooth, clean images.
Defocus Blur
A thin-lens camera model simulates depth of field. Objects at the focus distance appear sharp while objects closer or farther away are blurred, mimicking real camera optics.
Key Features
- Multi-sample anti-aliasing for smooth edges
- Diffuse, metal, and dielectric materials with configurable properties
- Depth of field via thin-lens camera simulation
- Gamma correction for accurate color output
- Random scene generation for complex renders
What I Learned
This project deepened my understanding of:
- Physically-based rendering concepts
- Vector math and ray-geometry intersection
- Monte Carlo methods and stochastic sampling
- C++ object-oriented design and polymorphism
- Image output and color space management