GAMES101 Lecture 16 - Ray Tracing 4 (Monte Carlo Path Tracing)

GAMES101_Lecture_16.pdf

I. Monte Carlo Integration

In the previous lecture we have described the light transport using the rendering equation:

(1)Lo(p,ωo)=Le(p,ωo)+Ω+Li(p,ωi)fr(p,ωi,ωo)(nωi)dωi

and we list it here as a reference.

 

Monte Carlo Integration

 

Definition: The Monte Carlo estimator for the definite integral abf(x)dx of given function f(x) is

(2)f(x)dx=FN=1Ni=1Nf(Xi)p(Xi)

where Xip(x) is a random variable.

Later on we will be using the Monte Carlo estimator to estimate the result of rendering equation, as a direct numerical calculation would be difficult.

 

Uniform random variable: for a random variable that has a constant probability to take an value on the interval [a,b], the probability is C=1ba.

 

Definition: The Basic Monte Carlo estimator abf(x)dx is

(3)FN=baNi=1nf(Xi)

 

II. Path Tracing

Motivation: Problems in Whitted-Style Ray Tracing

In summary, Whitted-style ray tracing:

Overall, physically wrong.

 

Path Tracing - Solving with Monte Carlo Estimator

As mentioned in the previous note Lecture15.md, the rendering equation consists of two separated parts:

The reflection part is just an integration of differential irradiance over the entire hemisphere, hence we can solve it using Monte Carlo integration.

To compute the radiance Lo at point p towards to camera, from equation 1 we have (ignoring the self-emission part)

Lo(p,ωo)=Ω+Li(p,ωi)fr(p,ωi,ωo)(nωi)dωi

Fancy as it is, it's still just an integration over directions.

We are sampling on the entire hemisphere, by applying equation 2 we have

Lo(x,ωo)=Ω+Li(x,ωi)fr(x,ωi,ωo)(nωi)dωi(4)1Ni=1NLi(x,ωi)fr(x,ωi,ωo)(nωi)p(ωi)

Note that here we have changed the notation to avoid confusion. Here:

 

We then have a version of algorithm:

 

This creates a correct shading algorithm. However, it is not computationally feasible, and incomputable in most cases.

As this is not the solution for computing the result, we will offer a computable solution hereafter.

 

Path Tracing

Definition: If N=1 in equation 4, then it is called path tracing.

Multiple samples will be made when computing for each pixel to estimate the correct result. The larger the number of samples are created, the more accurate the result will be.

 

Distributed Ray Tracing

Definition: If N>1 in equation 4, then it is called distributed ray tracing.

 

Ray Generation

In path tracing, multiple paths will be traced through each pixel, and the result will be the average radiance.

img-3

 

Stop Recursing Forever - Russian Roulette

The shading algorithm previously mentioned will recurse forever in some cases. The solution is to apply a technique called Russian Roulette.

What's the difference?

This version of path tracing is

img-4

 

Sampling the Light

Since we sample on the light, can we directly do integration on the light? The answer is yes.

img-1

The target is to make the rendering equation as an integral of dA, where dA is the differential area on the light source. We could convert dω appeared in equation 1 by the definition of solid angle - that is, the projected area on the unit sphere. Hence, we have

dω=dAcosθxx2

notice that θ represents the angle between xx and n, the surface normal of the light source.

Rewrite the rendering equation in this way gives

Lo(x,ωo)=Ω+Li(x,ωi)fr(x,ωi,ωo)cosθdωi=ALi(x,ωi)fr(x,ωi,ωo)cosθcosθxx2dA

where the interval for integration covers all light sources instead, and p=1/A.

 

 

The Final Version

Now we consider the radiance coming from two parts:

  1. light source (direct, no RR)

  2. other reflectors (indirect, RR).

RR: Russian Roulette.

 

The final version:

shade(p,ωo)

// Contribution from the light source

Uniformly sample the light at x where plight=1/A

Shoot a ray from x to x

if the light isn't blocked in the middle then

Ldirect=Lifrcosθcosθ/xx2/plight

// Contribution from other reflectors

Lindirect=0.0

Test Russian Roulette with probability PRR

Uniformly sample the hemisphere toward ωi, phemi=1/2π

Trace a ray r(p,ωi)

if the ray r hits a non-emitting object at q then

Lindirect=shade(q,ωi)frcosθ/phemi/PRR

 

return Ldirect+Lindirect

 

Correctness

The final version is almost 100% correct, a.k.a. PHOTO-REALISTIC.

img-2

 

Whitted-style Ray Tracing vs. Modern Concepts

 

Things we haven't covered