top of page

Monte Carlo Path Tracer

Updated: Apr 17, 2024

Implementation of C++/GLSL Monte Carlo path tracer, simulating physically correct behavior of light in a virtual scene.


Lo(p, ωo) = Le(p, ωo) + ∫S f(p, ωo, ωi) Li(p, ωi) V(p', p) |dot(ωi, N)| dωi


Implemented on the GPU-side, the final product includes the following lighting integrators:


  • Naive Integrator

  • Direct Lighting Integrator

  • Direct Integrator (with Multiple Importance Sampling)

  • Full Lighting Integrator



Additional features include environment mapping and environment-based global illumination, based on Unreal Engine's Lumen algorithm.


Naive integration

A basic rendering algorithm that calculates pixel colors by tracing rays from the camera view vector and computing accumulated light energy at each object intersection point. Performed until maximum depth or until a light source is hit, this technique does not account for more complex lighting effects like global illumination, resulting in simpler, noisier, (and often less realistic!) renderings.

Cornell Scene, Naive Integrator
Dielectric BxDF
Rough Mirror walls, Naive Integrator
Naive Integrator, (single pass)

Specular materials

Direct Integrator

A rendering algorithm that considers only direct lighting from spotlight, point light, and area light sources at each intersection point, resulting in more realistic renderings. Sampling light sources via cosine-weighted hemisphere sampling, it calculates the illumination without considering indirect light or multiple light bounces, making it computationally more efficient while still providing good results for scenes with primarily direct illumination.

Spot Light, Direct Integrator
Area Light, Direct Integrator

Point light, Direct Integrator

Direct Lighting, Multiple Importance Sampling

Direct lighting with multiple importance sampling calculates the probability of each light source contributing to a scene. This calculation allows prioritization of light sources that have a higher probability of significantly impacting the final rendered image, thereby improving efficiency and accuracy in lighting computations.

Direct Integrator (+MIS), 2 lights
DiElectric BxDF

Full Lighting Integrator

A full lighting integrator with global illumination combines direct and indirect lighting effects as well as reflections/refractions from environment maps. By tracing rays as they interact with surfaces and incorporating techniques like photon mapping, we get our most realistic and physically accurate renders.


Spotlight, Full Integrator
Cornell Scene, Environment Lighting
Cornell Scene, Full Integrator
Full Integrator, Mirrors

While individual processes differ based on the type of integrator, the general process for path tracing is as follows:

  1. Ray Generation: Per pixel, cast multiple rays from the camera into the scene.

  2. Intersection Testing: Check for ray-object collisions.

  3. Material Sampling: Simulate surface interactions via random sampling based on unique material BxDFs for materials including glass, metals, plastic, etc.

  4. Path Generation: Generate new outgoing rays based on surface properties.

  5. Recursive Tracing: Repeat steps for each new ray, until occlusion or maximum depth is reached.

  6. Light Accumulation: Accumulate light contributions along ray paths according to the light transport equation.

  7. Image Formation: Combine accumulated energy values to create final render.


Bình luận


bottom of page