In the previous lecture we have described the light transport using the rendering equation:
and we list it here as a reference.
Why: When we want to solve an integral, but it can be too difficult to solve analytically.
What & How: Estimate the integral of a function by averaging random samples of the function's value.
Definition: The Monte Carlo estimator for the definite integral
where
The more samples, the less variance
Sample on
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
Definition: The Basic Monte Carlo estimator
In summary, Whitted-style ray tracing:
Always perform specular reflections/refractions:
Where should the ray be reflected for glossy materials?
Incorrect implementation for glossy reflections, since the reflections in this case doesn't strictly follow the directions for specular reflections.
Stop bouncing at diffuse surfaces:
No reflections between diffuse materials.
Color-bleeding from global illumination.
Overall, physically wrong.
As mentioned in the previous note Lecture15.md
, the rendering equation consists of two separated parts:
the self-emission part, and
the reflection part.
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
Fancy as it is, it's still just an integration over directions.
We are sampling on the entire hemisphere, by applying equation
Note that here we have changed the notation to avoid confusion. Here:
and the PDF is
We then have a version of algorithm:
xxxxxxxxxx
shade(p, wo)
Randomly choose N directions wi~pdf
Lo = 0.0
for each wi
Trace a ray r(p, wi)
if ray r hits the light
Lo += (1 / N) * L_i * f_r * cosine / pdf(wi)
elseif ray r hits an object at point q
Lo += (1 / N) * shade(q, -wi) * f_r * cosine / pdf(wi)
return Lo
This creates a correct shading algorithm. However, it is not computationally feasible, and incomputable in most cases.
If
In most cases, it will recurse forever.
As this is not the solution for computing the result, we will offer a computable solution hereafter.
Definition: If
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.
Definition: If
In path tracing, multiple paths will be traced through each pixel, and the result will be the average radiance.
Otherwise the result will be noisy
xxxxxxxxxx
ray_generation(camPos, pixel)
Uniformly choose N sample positions within the pixel
pixel_radiance = 0.0
for each sample in the pixel
Shoot a ray at r(campos, cam_to_sample)
if ray r hits the scene at p
pixel_radiance += 1 / N * shade(p, sample_to_cam)
return pixel_radiance
The shading algorithm previously mentioned will recurse forever in some cases. The solution is to apply a technique called Russian Roulette.
xxxxxxxxxx
shade(p, wo)
//=================================
Manually specify a probability P_RR
Randomly select ksi in a uniform distribution in [0, 1]
If (ksi > P_RR) return 0.0;
//=================================
Randomly choose ONE direction wi~pdf(w)
Trace a ray r(p, wi)
if ray r hits the light
return L_i * f_r * cosine / pdf (wi) / P_RR
elseif ray r hits an object at q
return shade(q, -wi) * f_r * cosine / pdf(wi) / P_RR
What's the difference?
By introducing the probability
Unbiased estimator: Introducing the probability to shade doesn't affect the estimation much, as the expected value remains the same:
However, the variance is large.
Since the recursion follows the geometric distribution, the expected number of recursion is
In contrast, if you directly cutoff the bounce after certain number of recursions, the result is wrong, since the law of energy conservation isn't satisfied.
This version of path tracing is
correct, but
inefficient:
A lot of rays are wasted if we uniformly sample the hemisphere at the shading point.
Since we sample on the light, can we directly do integration on the light? The answer is yes.
The target is to make the rendering equation as an integral of
notice that
Rewrite the rendering equation in this way gives
where the interval for integration covers all light sources instead, and
Now we consider the radiance coming from two parts:
light source (direct, no RR)
other reflectors (indirect, RR).
RR: Russian Roulette.
The final version:
// Contribution from the light source
Uniformly sample the light at
where Shoot a ray from
to if the light isn't blocked in the middle then
// Contribution from other reflectors
Test Russian Roulette with probability
Uniformly sample the hemisphere toward
, Trace a ray
if the ray
hits a non-emitting object at then
return
The final version is almost
Previous
Ray-tracing equivalent to Whitted-style ray tracing
Modern (Prof.'s Definition)
The general solution of light transport, including
Unidirectional & Bidirectional Path Tracing
Photon Mapping
Photon mapping is a global illumination algorithm. It involves two main steps: photon emission and photon gathering. In the emission phase, photons are traced from light sources and stored in a photon map. In the gathering phase, these photons are used to estimate the indirect illumination at each point in the scene. Photon mapping is effective for simulating caustic effects and complex indirect lighting.
Metropolis Light Transport
A global illumination algorithm that uses a Markov Chain Monte Carlo (MCMC) method to sample light paths. It applies a random mutation process to generate new light paths, and a selection process based on the Metropolis-Hastings algorithm to accept or reject these paths. MLT is particularly useful for solving difficult light transport problems with complex lighting scenarios and is known for its ability to converge to accurate solutions.
VCM/UPBP
Uniformly sampling the hemisphere
How? Sampling
Monte Carlo integration allows arbitrary pdfs
What's the best choice? Importance sampling
Do random numbers matter?
Low discrepancy sequences
Multiple Importance Sampling
Sample the hemisphere and the light both
The radiance of a pixel is the average of radiance on all paths passing through it
Why? (Pixel reconstruction filter)
Is the radiance of a pixel the color of a pixel?
No. Gamma correction, curves, color space