Computer Graphics

Path Tracing and Monte Carlo

Pixar's RenderMan rendered Toy Story in 1995 with scanline rendering. Coco in 2017 used path tracing with 300-500 samples per pixel - each frame took 200 CPU hours. The difference is Kajiya's rendering equation (1986): a single mathematical formula for all light transport. Path tracing is a numerical solution of that equation. Understanding Monte Carlo integration and importance sampling explains why photorealistic rendering is possible - and why it is so slow.

  • **Blender Cycles / Mitsuba 3:** production path tracers in Python/CUDA. Mitsuba is a research platform for new rendering algorithms
  • **NVIDIA DLSS 3.5 (Ray Reconstruction):** a neural network trained on path traced data reconstructs a clean image from 1-spp noise - replacing thousands of samples
  • **Disney / Pixar / DreamWorks:** every production film uses path tracing with 256-4096 spp for final renders. The total lighting budget for Moana was 200 million CPU-hours

Monte Carlo Integration and the Rendering Equation

In 1986, James Kajiya published the rendering equation - a unified formula for all light transport: Lo(x, wo) = Le(x, wo) + integral[hemisphere] fr(x, wi, wo) * Li(x, wi) * cos(theta) * dwi. Here Lo is outgoing radiance, Le is emission, fr is the BRDF, Li is incoming radiance from direction wi. The hemisphere integral has no closed-form solution for complex scenes. The Monte Carlo method solves this: sampling N random directions wi gives an unbiased estimate of the integral. This is the principle behind Blender Cycles, Arnold, and RenderMan.

Monte Carlo estimate of integral I = integral f(x)dx is approximately (1/N) * sum f(Xi)/p(Xi), where Xi are samples from distribution p. With uniform hemisphere sampling p(wi) = 1/(2*pi), the estimate = (2*pi/N) * sum fr*Li*cos(theta). Error decays as O(1/sqrt(N)) - independent of dimensionality!

0

1

Sign In

The Monte Carlo estimate has error O(1/sqrt(N)). What does this mean for rendering quality?

Importance Sampling: BRDF and Light Sampling

Uniform hemisphere sampling is wasteful: most samples from dark directions contribute zero. Importance sampling takes more samples where the integrand is large. For Lambertian BRDF the optimal strategy is cosine-weighted sampling: PDF = cos(theta)/pi. For GGX (metallic PBR) - half-vector distribution sampling. Multiple Importance Sampling (MIS) by Veach (1995) optimally combines strategies: weights samples inversely proportional to variance. MIS is used in Cycles, Arnold, Mitsuba.

MIS balance weight: w_k(x) = n_k * p_k(x) / sum_j n_j * p_j(x). The balance heuristic is variance-optimal among linear combinations. For BRDF + Light sampling: w_brdf = p_brdf / (p_brdf + p_light), w_light = p_light / (p_brdf + p_light).

For a glossy material with a sharp specular peak, BRDF sampling is best. Why is uniform hemisphere sampling inefficient in this case?

BRDF: Physically Based Materials

The BRDF (Bidirectional Reflectance Distribution Function) fr(wi, wo) describes how a surface reflects light: the ratio of outgoing radiance in direction wo to irradiance from direction wi. A physically correct BRDF satisfies: (1) Helmholtz reciprocity fr(wi,wo) = fr(wo,wi), (2) energy conservation integral fr*cos(theta)*dwi <= 1. Disney BRDF (Burley 2012) is the industry standard: metallic-roughness model with 10 parameters. GGX (Trowbridge-Reitz) is the microfacet distribution for gloss, used in Unreal, Unity, Blender.

GGX NDF: D(h) = alpha^2 / (pi * ((n*h)^2*(alpha^2-1)+1)^2), where h is the half-vector, alpha = roughness^2. GGX has a longer tail than Blinn-Phong - more physically accurate highlights. Geometry term G (self-shadowing) and Fresnel F(wi, h) together form specular BRDF: f_specular = D*G*F / (4*(n*wi)*(n*wo)).

Disney BRDF uses a metallic parameter from 0 to 1. What changes in shading from metallic=1 (metal) to metallic=0 (dielectric)?

Path Tracer Convergence: Denoising and Variance Reduction

A path tracer converges to the correct image as samples increase, but slowly: noise decays as 1/sqrt(N). Production rendering (film) requires 4096+ spp. Real-time games use 1-4 spp with AI denoising. NVIDIA DLSS 3.5 (Ray Reconstruction) uses a neural network to denoise 1-spp traces. OptiX AI Denoiser is an HDR denoiser trained on millions of renders. Variance reduction techniques: Next Event Estimation, Russian Roulette for path termination, Quasi-Monte Carlo (Halton, Sobol sequences) instead of pseudorandom numbers.

Russian Roulette: when path weight w < threshold, with probability (1-p) the path terminates; with probability p it continues with weight w/p. This is unbiased: E[w/p * p + 0 * (1-p)] = w. Quasi-Monte Carlo (QMC) uses low-discrepancy sequences (Halton, Sobol) - error O(log^d(N)/N) vs O(1/sqrt(N)) for standard MC.

More samples always give a better result - with enough N a path tracer will produce a perfect image

Monte Carlo has irreducible noise O(1/sqrt(N)). Practical rendering requires variance reduction techniques and denoising

At 1 spp - visible noise. At 4096 spp - clean image, but 4096x longer. AI denoising (DLSS Ray Reconstruction, OptiX Denoiser) replaces 4096 spp with 4 spp + neural network - comparable quality at 1/1000 the time. A physically exact result requires infinitely many samples.

Russian Roulette terminates paths with low throughput with probability (1-p) and continues with weight 1/p. Why does this not introduce bias?

Key Ideas

  • **Rendering equation:** Lo = Le + integral fr*Li*cos*dwi. Path tracing solves it via Monte Carlo - the only practical approach for arbitrary scenes.
  • **MC error O(1/sqrt(N)):** to halve noise requires four times as many samples. This motivates importance sampling and AI denoising.
  • **Importance sampling:** sample where the function is large. Cosine-weighted for Lambertian, GGX-sampling for metal/gloss. MIS combines strategies optimally.
  • **Practical tools:** Russian Roulette (unbiased termination), Next Event Estimation (direct light), QMC sequences - variance reduction without bias.

Related Topics

Path tracing extends Monte Carlo approaches to global illumination rendering.

  • Ray Tracing: Fundamentals — Path tracing extends Whitted ray tracing by adding random hemisphere sampling
  • Lighting: Phong, PBR — Disney/GGX BRDF is the material model used inside the path tracer

Вопросы для размышления

  • DLSS Ray Reconstruction replaces 4096 spp with 4 spp + a neural network. Is the result physically correct? What exactly does the network do - refine the integral or 'guess' missing information?
  • Quasi-Monte Carlo sequences (Halton, Sobol) give O(log^d/N) error vs O(1/sqrt(N)) for standard MC. Why is QMC not always better? Under what conditions is standard MC preferable?
  • Next Event Estimation (NEE) traces a shadow ray directly to the light source, dramatically reducing noise. But NEE does not apply to specular surfaces. Why? How does BDPT (bidirectional path tracing) solve this problem?

Связанные уроки

  • stat-05-hypothesis
Path Tracing and Monte Carlo