Monte Carlo Path Tracer

Completed: January 2025
  • C++
  • GLSL

Overview

This was one of the major projects for CIS 5610. It uses Monte Carlo approximation to "solve" the Light Transport Equation:

\[ L_o(\mathbf{x}, \boldsymbol{\omega}_o) = L_e(\mathbf{x}, \boldsymbol{\omega}_o) \;+\; \int_{\Omega} f_r\!\bigl(\mathbf{x}, \boldsymbol{\omega}_i, \boldsymbol{\omega}_o\bigr) \,L_i\!\bigl(\mathbf{x}, \boldsymbol{\omega}_i\bigr) \,(\mathbf{n} \cdot \boldsymbol{\omega}_i) \,d\boldsymbol{\omega}_i \]

Optimizations such as Multiple Importance Sampling and Cosine weighted sampling were used to improve the time it takes for a rendered image to converge. This renderer supports a variety of material types including Lambertian, Specular, Transmissive, Emmisive, and Micro-facet models. Different light types including area lights, sphere lights, point lights, spot lights, and environment lights were implemented. With these features available, custom scenes could be created and imported via a .JSON file reader.

Custom Scene Renders

Screenshot 1
Glass sphere in a micro-facet mirror box
Screenshot 2
Glass cubes
Screenshot 3
Glass Cubes in a micro-facet mirror box

Breakdown

Multiple Importance Sampling

With Monte Carlo estimation, a PDF distribution is needed to adjust the contributions of the incomeing rays and approximate the light integral. A sigle function that matches both the PDF of our light source and the PDF of the BRDF at a surface point, we importance-sample each PDF separately, then combine the results using appropriate weights. Basically, you get the best of both methods by weighting one methods contribution more deppending on how well the pdf matches the smapled ray.

Depending on the characteristics of the light and the BRDF, one sampling strategy may be far more effective than the other. For example, with a Specular BRDF, sampling only the light's PDF can miss narrow reflections, thus under-sampling bright highlights, but sampling with the BRDFs PDF would work just fine. On the hand, for a diffuse BRDF, sampling only the BRDF's PDF can miss small lights, especially if they occupy a tiny solid angle in the scene.

For each sampling type—BSDF and Direct—we draw samples from both the surface’s BRDF distribution (pB(x)) and the light’s distribution (pL(x)). That is, we sample with both distributions for both sampling types (four samples in total). We then apply the appropriate weight wi or wj based on the Balance Heuristic (see below) and sum the contributions. This helps ensure that no matter if the BRDF is highly specular or very diffuse, or the lights are large or small, we capture all significant lighting paths with minimal noise.

To get the correct weighting, we use the Balance Heuristic:

\[ w_i = \frac{N_L \, p_L(x)}{N_L \, p_L(x) + N_B \, p_B(x)}, \quad w_j = \frac{N_B \, p_B(x)}{N_L \, p_L(x) + N_B \, p_B(x)}. \]

When the final radiance is computed, each sample's contribution is:

\[ L_{\text{final}}(x_i) = \frac{f(x_i)}{N_L \, p_L(x_i)} \, w_i, \quad L_{\text{final}}(x_j) = \frac{f(x_j)}{N_B \, p_B(x_j)} \, w_j. \]

This way, samples that are very likely under the BRDF PDF but also well-covered by the light PDF won't be doubly counted, and vice versa. The Balance Heuristic effectively merges both sampling strategies so that each important region of the integrand (bright lights, glossy reflections, etc.) receives enough samples.

veach
Varying light size and deffuse levels (MIS)

Test Scenes

Screenshot 1
Single area light and enviroment light box (MIS)
Screenshot 2
Enviroment light box (MIS)
Screenshot 3
Enviroment lgith with mirror box (MIS)
Screenshot 3
Point light box (MIS)
Screenshot 3
Double area light box (MIS)
Screenshot 3
Spot light box (MIS)
Screenshot 3
Glass ball box (BRDF Sampling)
Screenshot 3
Transmissive ball box (BRDF Sampling)
Screenshot 3
Micro-facet box (MIS)