Monte Carlo Path Tracer
- Morgan Herrmann
- Apr 17, 2024
- 2 min read
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.
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.
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.
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.
While individual processes differ based on the type of integrator, the general process for path tracing is as follows:
Ray Generation: Per pixel, cast multiple rays from the camera into the scene.
Intersection Testing: Check for ray-object collisions.
Material Sampling: Simulate surface interactions via random sampling based on unique material BxDFs for materials including glass, metals, plastic, etc.
Path Generation: Generate new outgoing rays based on surface properties.
Recursive Tracing: Repeat steps for each new ray, until occlusion or maximum depth is reached.
Light Accumulation: Accumulate light contributions along ray paths according to the light transport equation.
Image Formation: Combine accumulated energy values to create final render.
Bình luận