rendering: importance sampling - tu wien
TRANSCRIPT
Rendering: Importance Sampling
Bernhard Kerbl
Research Division of Computer Graphics
Institute of Visual Computing & Human-Centered Technology
TU Wien, AustriaWith slides based on material by Jaakko Lehtinen, used with permission
Todayโs Goal
Improve the efficiency of Monte Carlo with importance sampling
Understand how we can produce custom distributions in simple 1D, 2D and 3D domains by warping simple, uniform random variables
Learn how we can transform samples between cartesian and non-cartesian domains (e.g., from polar (๐, ๐) to XYZ vectors)
Understand how we can incorporate these steps into path tracing
Rendering โ Importance Sampling 2
Importance Sampling
All these things sound tediousโฆ why do we need to create samples from arbitrary distributions? In different domains even?
When we sample, e.g., the hemisphere, we can use any PDF we like
We know the selection of the proper ๐ ๐ฅ as importance samplingRendering โ Importance Sampling 3
๐(๐ฅ)
๐(๐ฅ)
๐(๐ฅ)
๐(๐ฅ)
Bad sampling (high variance) Importance sampling (low variance)
Importance Sampling
Remember: if possible, you want a PDF ๐ ๐ฅ that mimics ๐ ๐ฅ !
Rendering โ Importance Sampling 4
Letโs look at an application for importance sampling in practice
Consider a target function ๐(๐ฅ)
You want to compute its integral, but have no closed-form solution or donโt know what ๐(๐ฅ) is?
Clearly, a case for Monte Carlo
Monte Carlo Integration with Importance Sampling
Rendering โ Importance Sampling 5
If we take another look, the shape of this function seems familiarโฆ
It appears to be quite close to ๐ฅ2!
We already know that uniform sampling of ๐(๐ฅ) is only one way to do Monte Carlo integrationโฆ
Letโs try instead with ๐ ๐ฅ โ ๐ฅ2
Monte Carlo Integration with Importance Sampling
Rendering โ Importance Sampling 6
Both methods convergetowards the same result
But the importance-sampledmethod converges quicker!
Letโs see what the codebehind it looks like..
Uniform vs Importance Sampling (Python)
integrate_mc(0, 100, N, f, p_uniform, gen_uniform) vs integrate_mc(0, 100, N, f, p_x2, gen_x2)
Rendering โ Importance Sampling 7
Uniform vs Importance Sampling (Python)
Rendering โ Importance Sampling 8
integrate_mc(0, 100, N, f, p_uniform, gen_uniform) vs integrate_mc(0, 100, N, f, p_x2, gen_x2)
def integrate_mc(a: float, b: float, N: int, f, p, gen):
X = gen(a, b, N)
estimates = f(X)/p(X, a, b)
result = estimates.sum() / N
return result
def p_uniform(x, a: float, b: float):
return x/(b-a)
def p_x2(x, a: float, b: float):
b3 = ((b**3)/3)
a3 = ((a**3)/3)
return x**2/(b3-a3)
def gen_uniform(a: float, b: float, N: int):
xi = np.random.rand(N)
return xi * (b - a) + a
def gen_x2(a: float, b: float, N: int):
xi = np.random.rand(N)
b3 = (b**3)
a3 = (a**3)
return (a3+xi*(b3-a3))**(1.0/3.0)
By the end of the day, thisshould make sense to you!
Last time, we did uniform hemisphere sampling, and it worked
But perhaps we can also useimportance sampling here?
Can we perhaps importance-sample the rendering equation?
The hemisphere is a peculiar domain. Sampling it with arbitrary distributions is a little bit more complexโฆ
Importance Sampling on the Hemisphere
Rendering โ Importance Sampling 9
Todayโs Roadmap
Rendering โ Importance Sampling 10
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Importance
Sampling Unlocked!
Sampling the Unit Disk 2:
Crossing Domains
Todayโs Roadmap
Rendering โ Importance Sampling 11
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Sampling the Unit Disk 2:
Crossing Domains
Importance
Sampling Unlocked!
Discrete Random Variables
In daily life, we are mostly confronted with discrete random results
A coin flip
Toss of a die
Cards in a deck
Each possible outcome of a random variable is associated with a specific probability ๐. Probabilities must sum up to 1 (100%)
E.g., a fair die: ๐ โ 1,2,3,4,5,6 and ๐1 = ๐2 = โฏ = ๐6 =1
6
Rendering โ Monte Carlo Integration I 12
Continuous Random Variables
A continuous random variable ๐ with a given range [๐, ๐) can assume any value ๐๐ that fulfills ๐ โค ๐๐ < ๐
Working with continuous variables generalizes the methodology for many complex evaluations that depend on probability theory
There are infinitely many possible outcomes and, consequently, the observation of any specific event has with vanishing probability
How can we find the probabilities for continuous variables?[2]
Rendering โ Importance Sampling 13
Cumulative Distribution Function (CDF)
For continuous variables, we cannot assign probabilities to values
The cumulative distribution function (CDF) lets us compute the probability of a variable taking on a value in a specified range [2]
We use notation ๐๐ ๐ฅ for the CDF of ๐โs distribution, which yields the probability of ๐ taking on any value โค ๐ฅ
Rendering โ Importance Sampling 14
0 1
If ๐ can take on any value with equal probability, what is the probability of ๐ = 0.5?
?
๐๐ ๐ โ ๐๐ ๐ = ๐๐ ๐ โค ๐๐ โค ๐
Read as: ๐กโ๐ ๐๐๐๐๐๐๐๐๐๐ก๐ฆ ๐๐ ๐ ๐ก๐๐๐๐๐ ๐๐ ๐๐๐ฆ ๐ฃ๐๐๐ข๐ ๐๐๐๐ 0 ๐ก๐ ๐,๐๐๐๐ข๐ ๐กโ๐ ๐๐๐๐๐๐๐๐๐๐ก๐ฆ ๐๐ ๐ ๐ก๐๐๐๐๐ ๐๐ ๐๐๐ฆ ๐ฃ๐๐๐ข๐ ๐๐๐๐ 0 ๐ก๐ ๐
Example: uniform variable ฮพgenerates values in range [0, 1):
๐๐ ๐ฅ = ๐ฅ
๐๐ 0.75 โ P๐ 0. 5 = 0.25
Probability for a Range with CDF
Rendering โ Importance Sampling 15
๐ฆ
๐ฅ0 1
1
๐(๐ฅ)
Properties of the CDF
CDF is bounded by [0, 1] and monotonic increasing
Probability of no outcome is 0, the probability of some outcome is 1
Die: Rolling a number between 1 and 6 cannot be less probable than rolling a number between 1 and 5
CDFs can be applied for discrete and continuous random variables
How do we compute the CDF?
Rendering โ Importance Sampling 16
๐ฆ
๐ฅ0
1๐(๐ฅ)
Determine the limits [๐, ๐] of your variable ๐
For each outcome, find its probability ๐๐, โฆ , ๐๐The CDF of that variable is then a function ๐๐ ๐ฅ = ฯ๐=๐
๐ฅ ๐๐
Computing the CDF for Discrete Random Variables
Rendering โ Importance Sampling 17
๐ฅ0
1
๐0 ๐0 ๐0 ๐0
๐1 ๐1 ๐1
๐3
๐2๐2
๐ฅ0
1
๐0 ๐1
๐3๐2
Outcome Probabilities Cumulated Probabilities (CDF)
Probability Density Function (PDF)
The PDF ๐(๐ฅ) is the derivative of the CDF ๐(๐ฅ): ๐ ๐ฅ =๐๐(๐ฅ)
๐๐ฅ
For a PDF ๐(๐ฅ), ๐ ๐ฅ = โซ ๐ ๐ฅ ๐๐ฅ and โซ๐๐๐ ๐ฅ ๐๐ฅ = ๐ ๐ โ ๐(๐)
๐(๐ฅ) must be positive everywhere: a negative value would mean we
can find [๐, ๐] such that โซ๐๐๐ ๐ฅ ๐๐ฅ has a negative probability
๐๐(๐ฅ) can be understood as the relative probability of ๐๐ = ๐ฅ.I.e., if ๐๐ ๐ = 2๐๐(๐), then ๐๐ = ๐ is twice as likely as ๐๐ = ๐
Rendering โ Importance Sampling 18
Notes about the PDF
Notation may look like probability, but PDF values can be >1!
For both discrete and continuous variables, we can referenceโ๐(๐ฅ)โ to describe their distribution
Summary: for a continuous variable ๐ with a known, integrable PDF, we can find the CDF and probabilities of ๐ landing in a given range
โฆis this actually helpful?
Rendering โ Importance Sampling 19
Todayโs Roadmap
Rendering โ Importance Sampling 20
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Importance
Sampling Unlocked!
Sampling the Unit Disk 2:
Crossing Domains
Creating Variables with Custom Distributions
By discovering the CDF, we have found a powerful new tool
The function is often invertible: this means, we can generate random variables with a desired distribution!
Rationale: Since the CDF is monotonic increasing, there is a unique value of ๐๐ ๐ฅ for every ๐ฅ with ๐๐ ๐ฅ > 0
More informally, if we plot a 1D CDF, any ๐ฅ value that ๐ can take on has a unique, corresponding coordinate on the ๐ฆ-axis
Rendering โ Importance Sampling 21
Basic Sampling with Canonical Random Variables
We want to generate samples for a custom distribution from a random input that we can easily obtain in a computer environment
Our assumed input is the canonical random variable ๐:
continuous (i.e., a real data type)
with uniform distribution
in the range [0, 1)
Goal: warp samples of ๐ to ones distributed according to some ๐(๐ฅ)
Rendering โ Importance Sampling 22
The Canonical Random Variable
Our assumed default input variable
PDF for ๐ is 1 in range [0,1) and 0 everywhere else
CDF for ๐ is linear
Important property: we have equality ๐ ๐๐ = ๐๐
Rendering โ Importance Sampling 23
The Inversion Method
For discrete variables: we draw ๐ and iterate event probabilities
When their sum first surpasses ๐, we have found ๐๐For continuous variables: exploit ๐๐โs bijectivity and use its inverse!
We can use canonic ๐ to compute ๐๐ = ๐๐โ1(๐) according to ๐๐(๐ฅ)
Rendering โ Importance Sampling 24
๐
0
1๐(๐ฅ)
๐๐
๐
0
1
๐๐
๐0 ๐0 ๐0 ๐0
๐1 ๐1 ๐1
๐3
๐2๐2
Example: Exponential Distribution
Used mainly for estimation of time intervals between two events
The probability of a value decreases exponentially
Needs additional parameter ๐, often called rate parameter
We can find its PDF and CDF in most probability text books
๐ ๐ฅ, ๐ = ๐๐โ๐๐ฅ
๐ ๐ฅ, ๐ = 1 โ eโ๐๐ฅ, ๐โ1 ๐ฅโฒ, ๐ = โlog(1โ๐ฅ)
๐
Rendering โ Importance Sampling 25
Warping Uniform To Exponential Distribution
Rendering โ Importance Sampling 26
const size_t NUM_SAMPLES = 10'000;
std::array<double, NUM_SAMPLES> exponential_samples{};std::array<double, NUM_SAMPLES> uniform_samples{};std::array<double, NUM_SAMPLES> warped_samples{};
void inversionDemo(){
const double LAMBDA = 5.0;
std::default_random_engine rand_eng_uniform(0xdecaf);std::default_random_engine rand_eng_exponential(0xcaffe);
std::uniform_real_distribution<double> uniform_dist(0.0, 1.0);std::exponential_distribution<double> exponential_dist(LAMBDA);
for (int i = 0; i < NUM_SAMPLES; i++){
auto R_i = exponential_dist(rand_eng_exponential);exponential_samples[i] = R_i;
// uniform distribution: CDF(x) = xauto x_ = uniform_samples[i] = uniform_dist(rand_eng_uniform);
auto X_i = -std::log(1.0 - x_) / LAMBDA;warped_samples[i] = X_i;
}}
Histograms of generated samples
Warping Uniform To Exponential Distribution
Rendering โ Importance Sampling 27
๐๐ = ๐๐โ1 ๐๐
๐๐
๐ ๐
๐๐
Warping Uniform To Exponential Distribution
Rendering โ Importance Sampling 28
const size_t NUM_SAMPLES = 10'000;
std::array<double, NUM_SAMPLES> exponential_samples{};std::array<double, NUM_SAMPLES> uniform_samples{};std::array<double, NUM_SAMPLES> warped_samples{};
void inversionDemo(){
const double LAMBDA = 5.0;
std::default_random_engine rand_eng_uniform(0xdecaf);std::default_random_engine rand_eng_exponential(0xcaffe);
std::uniform_real_distribution<double> uniform_dist(0.0, 1.0);std::exponential_distribution<double> exponential_dist(LAMBDA);
for (int i = 0; i < NUM_SAMPLES; i++){
auto R_i = exponential_dist(rand_eng_exponential);exponential_samples[i] = R_i;
// uniform distribution: CDF(x) = xauto x_ = uniform_samples[i] = uniform_dist(rand_eng_uniform);
auto X_i = -std::log(1.0 - x_) / LAMBDA;warped_samples[i] = X_i;
}}
This is actually the implementation
in many standard libraries anyway
Mix Multiple Random Variables
Letโs add another variable and combine them for 2D output
In doing so, we are extending our sampling domain
The sampling domain is defined by
The number of variables, and
Their respective ranges
Think of the domain as a space with the axes representing variables
Rendering โ Importance Sampling 29
Joint PDF
If multiple variables are in a domain, the joint PDF probability density of a given point in that domain depends on all of them
In the simplest case, with independent variables ๐ and ๐, the joint PDF of their shared domain PDF is simply ๐ ๐ฅ, ๐ฆ = ๐๐ ๐ฅ ๐๐(๐ฆ)
We can sample independent variables in a domain by computing and sampling the inverse of their respective CDFs, separately
Rendering โ Importance Sampling 30
2D with ๐ = ๐. For ๐, use ๐ โ [0,๐
2) and ๐ ๐ฅ = cos ๐ฅ
๐๐ ๐ฅ = โซ ๐ ๐ฅ ๐๐ฅ = โซcos ๐ฅ ๐๐ฅ = sin ๐ฅ
๐๐โ1 ๐ = sinโ1(๐)
Inversion Method Examples in 2D
Rendering โ Importance Sampling 31
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
Y
X
void inversionDemo2D(){
std::default_random_engine x_rand_eng(0xdecaf);std::default_random_engine y_rand_eng(0xcaffe);
std::uniform_real_distribution<double> uniform_dist;
for (int i = 0; i < NUM_SAMPLES; i++){
auto x_ = uniform_dist(x_rand_eng);auto y_ = uniform_dist(y_rand_eng);
auto X_i = asin(x_);auto Y_i = y_;samples2D[i] = std::make_pair(X_i, Y_i);
}}
๐ and ๐ in range 0,1
For both variables, ๐ ๐ฃ = 2๐ฃ, ๐ ๐ฃ = ๐ฃ2, ๐โ1 ๐ = ๐
Inversion Method Examples in 2D
Rendering โ Importance Sampling 32
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Y
X
std::array<std::pair<double, double>, NUM_SAMPLES> samples2D{};
void inversionDemo2D(){
std::default_random_engine x_rand_eng(0xdecaf);std::default_random_engine y_rand_eng(0xcaffe);
std::uniform_real_distribution<double> uniform_dist;
for (int i = 0; i < NUM_SAMPLES; i++){
// uniform distribution: CDF(x) = x auto x_ = uniform_dist(x_rand_eng); auto y_ = uniform_dist(y_rand_eng);
auto X_i = sqrt(x_);auto Y_i = sqrt(y_);
samples2D[i] = std::make_pair(X_i, Y_i);}
}
Letโs pick a slow-growing portion of the distribution function
Compared to 0,1 , cumulative density only doubles in 2,4
Choosing a Different Range
Rendering โ Importance Sampling 33
๐ ๐ฅ = 2๐ฅ ๐ ๐ฅ = ๐ฅ2 (๐๐๐๐๐๐๐ก)
Try ๐ and ๐ in range 2,4
For both variables, ๐ ๐ฃ = 2๐ฃ, ๐ ๐ฃ = ๐ฃ2, ๐โ1 ๐ = ๐
Nothing happens.
How can we adapt variable ranges?
Something is missing!
Inversion Method Examples in 2D
Rendering โ Importance Sampling 34
0
0.5
1
1.5
2
2.5
3
3.5
4
0 0.5 1 1.5 2 2.5 3 3.5 4
Y
X
Consider a given range from ๐ to ๐ for a variable and a candidate PDF ๐(๐ฅ) with the desired distribution shape
If โซ๐๐๐ ๐ฅ ๐๐ฅ โ 1, ๐ ๐ฅ is not a valid PDF for this variable
The probability that the result is one of all possible results โ 100%
To fix this, we compute the proportionality constant ๐ = โซ๐๐๐ ๐ฅ ๐๐ฅ
and compute a valid ๐ ๐ฅ =๐น(๐ฅ)
๐and ๐ ๐ฅ =
๐(๐ฅ)
๐โ ๐(๐ฅ)
Restricting the PDF / CDF
Rendering โ Importance Sampling 35
For range [๐, ๐] where ๐ โ 0, we adda constant offset ๐ = โ๐(๐)
Try ๐, ๐ โ 2,4 and ๐ ๐ฃ = 2๐ฃ again
We compute ๐๐ = ๐๐ = โซ242๐ฃ ๐๐ฃ = 12 and add ๐ = โ
4
12to get:
๐ ๐ฃ =๐ฃ2โ4
12, ๐โ1 ๐ = 2 3 โ ๐ + 1, ๐ ๐ฃ =
2๐ฃ
12
Restricting the PDF / CDF
Rendering โ Importance Sampling 36
2
2.2
2.4
2.6
2.8
3
3.2
3.4
3.6
3.8
4
2 2.5 3 3.5 4
Y
X
The Inversion Method, Completed
Find a candidate function ๐(๐ฅ) with the desired distribution shape
Choose the range [๐, ๐] in ๐(๐ฅ) you want your variable to imitate
Determine the indefinite integral ๐น ๐ฅ = โซ ๐ ๐ฅ ๐๐ฅ
Compute the proportionality constant ๐ = ๐น ๐ โ ๐น(๐)
The CDF for the new variable ๐ is ๐๐ ๐ฅ =๐น ๐ฅ โ๐น(๐)
๐
Compute the inverse of the CDF ๐๐โ1 ๐
Use ๐๐โ1(๐) to warp the samples of a canonic random variable
so that they are distributed with ๐ ๐ฅ =๐(๐ฅ)
๐in the range [๐, ๐)
Rendering โ Importance Sampling 37
Deriving the ๐ ๐ฅ โ ๐ฅ2 Sample Generation Functions
integrate_mc(0, 100, N, f, p_uniform, gen_uniform) vs integrate_mc(0, 100, N, f, p_x2, gen_x2)
def integrate_mc(a: float, b: float, N: int, f, p, gen):
X = gen(a, b, N)
estimates = f(X)/p(X, a, b)
result = estimates.sum() / N
return result
def p_uniform(x, a: float, b: float):
return x/(b-a)
def p_x2(x, a: float, b: float):
b3 = ((b**3)/3)
a3 = ((a**3)/3)
return x**2/(b3-a3)
Rendering โ Importance Sampling 38
integrate_mc(0, 100, N, f, p_uniform, gen_uniform) vs integrate_mc(0, 100, N, f, p_x2, gen_x2)
def integrate_mc(a: float, b: float, N: int, f, p, gen):
X = gen(a, b, N)
estimates = f(X)/p(X, a, b)
result = estimates.sum() / N
return result
def p_uniform(x, a: float, b: float):
return x/(b-a)
def p_x2(x, a: float, b: float):
b3 = ((b**3)/3)
a3 = ((a**3)/3)
return x**2/(b3-a3)
Deriving the ๐ ๐ฅ โ ๐ฅ2 Sample Generation Functions
Rendering โ Importance Sampling 39
๐น ๐ฅ =๐ฅ3
3, ๐ =
๐3 โ ๐3
3,
๐ ๐ฅ =๐ฅ2
๐,
๐๐โ1 ๐ =
3๐3 + ๐(๐3 โ ๐3),
def gen_uniform(a: float, b: float, N: int):
xi = np.random.rand(N)
return xi * (b - a) + a
def gen_x2(a: float, b: float, N: int):
xi = np.random.rand(N)
b3 = (b**3)
a3 = (a**3)
return (a3+xi*(b3-a3))**(1.0/3.0)
Todayโs Roadmap
Rendering โ Importance Sampling 40
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Importance
Sampling Unlocked!
Sampling the Unit Disk 2:
Crossing Domains
Sampling a Unit Disk
Imagine we have a disk-shaped surface with radius ๐ = 1 that registers incoming light (color) from directional light sources
As an exercise, we want to approximate the total incoming light over the diskโs surface area
We integrate over an area of size ๐
We will use the Monte Carlo integral for that
Rendering โ Importance Sampling 41
2
2r = 1
Uniformly Sampling the Unit Disk
If we can manage to uniformly sample the disk, then we can compute the Monte Carlo integral as a simple average ร ๐
By drawing uniform samples in ๐ฅ and ๐ฆ, we cannot cover the area precisely
Inscribed square: information lost
Circumscribed square: unnecessary samples
Rendering โ Importance Sampling 42
Uniformly Sampling the Unit Disk
If we can manage to uniformly sample the disk, then we can compute the Monte Carlo integral as a simple average
By drawing uniform samples in ๐ฅ and ๐ฆ, we cannot cover the area precisely
Inscribed square: information lost
Circumscribed square: unnecessary samples
Rendering โ Importance Sampling 43
Uniformly Sampling the Unit Disk
If we can manage to uniformly sample the disk, then we can compute the Monte Carlo integral as a simple average
By drawing uniform samples in ๐ฅ and ๐ฆ, we cannot cover the area precisely
Inscribed square: information lost
Circumscribed square: unnecessary samples
Rendering โ Importance Sampling 44
Back to the Unit Disk
We do not want to waste samples if we can avoid it
Instead, find a way to generate uniform samples on the disk
Create samples in a non-cartesian domain: 2D polar coordinates
Polar coordinates defined by radius ๐ โ [0,1) and angle ๐ โ [0,2๐)
Transformation to cartesian coordinates: ๐ฅ = ๐ sin ๐y = ๐ cos ๐
Rendering โ Importance Sampling 45
Uniformly Sampling the Unit Disk?
Convert two ๐ to ranges 0, 1 , [0,2๐) to get polar coordinates
Convert to cartesian coordinates
Rendering โ Importance Sampling 46
void sampleUnitDisk(){
std::default_random_engine r_rand_eng(0xdecaf);std::default_random_engine theta_rand_eng(0xcaffe);
std::uniform_real_distribution<double> uniform_dist(0.0, 1.0);
for (int i = 0; i < NUM_SAMPLES; i++){
auto r = uniform_dist(r_rand_eng);auto theta = uniform_dist(theta_rand_eng) * 2 * M_PI;auto x = r * sin(theta);auto y = r * cos(theta);
samples2D[i] = std::make_pair(x, y);}
}
We successfully sampled the unit disk in the proper range
However, the distribution is notuniform with respect to the area
Samples clump together at center
Averaging those samples will give us a skewed result for the integral!
Clumping
-1
-0.5
0
0.5
1
-1 -0.5 0 0.5 1
Rendering โ Importance Sampling 47
Uniformly Sampling the Unit Disk: A Solution
The area of a disk is proportional to ๐2, times a constant factor ๐
If we see the disk as concentric rings of width ฮ๐, the ๐ inner rings
up to radius ๐๐ = ๐ฮ๐ should contain ๐๐
๐
2๐ out of ๐ total samples
Conversely, the ๐๐กโ sample should lie in the ring at radius ๐๐ = ๐๐
๐
Since ๐ is uniform in [0, 1), we can switch ๐
๐for ๐๐ to get ๐๐ = ๐ ๐๐
Rendering โ Importance Sampling 48
Uniformly Sampling the Unit Disk: A Solution
It works, and it is not even a bad way toarrive at the correct solution
However, for more complex scenarios, wemight struggle to find the solution so easily
With the tools we introduced earlier (and a few new tricks), we can formalize this process for arbitrary setups!
Rendering โ Importance Sampling 49
-1
-0.5
0
0.5
1
-1 -0.5 0 0.5 1
-1
-0.5
0
0.5
1
-1 -0.5 0 0.5 1
Todayโs Roadmap
Rendering โ Importance Sampling 50
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Importance
Sampling Unlocked!
Sampling the Unit Disk 2:
Crossing Domains
Another Look at the PDF
Rendering โ Importance Sampling
We saw samples being โwarpedโ: we can interpret the inversion method as a spatial transformation of uniform samples
Letโs treat the space in the input domain like a grid of infinitesimal hypercubes: segments in 1D, squares in 2D and cubes in 3D[5]
If we warp a domain where each variable is ๐ to one with joint PDF
๐๐ท, then 1
๐๐ทis the change in volume of the hypercubes after warping
51
Visualizing the PDF in 2D
The left represents our inputs and the right our target distribution
This time, we warp grid coordinates with the inversion method
Rendering โ Importance Sampling 52
ฮพ1, ฮพ2 ๐ = ฮพ2 and ๐ โ 0,1 , ๐๐ ๐ฅ = 2๐ฅ
ฮพ1, ฮพ2
The areas of all 2D hypercubes (grid cells) are scaled by 1
๐๐ ๐ฅ ๐๐(๐ฆ)
๐๐ ๐ฅ = 2๐ฅ, cells on the right at (1, ๐ฆ) are half their original width
Visualizing the PDF in 2D
Rendering โ Importance Sampling 53
๐ = ฮพ2 and ๐ โ 0,1 , ๐๐ ๐ฅ = 2๐ฅ
Earlier, we saw samples ๐, ๐ โ 0,1 with ๐๐ ๐ฅ = 2๐ฅ, ๐๐(๐ฆ) = 2๐ฆ
Visualizing the PDF in 2D
Rendering โ Importance Sampling 54
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
2D Variables with Linear PDFs
In this 2D setup, we have joint PDF ๐ ๐ฅ, ๐ฆ = ๐๐ ๐ฅ ๐๐ ๐ฆ = 4๐ฅ๐ฆ
Space near point (1,1) is compressed down to 1
4of its original size
Visualizing the PDF in 2D
Rendering โ Importance Sampling 55
ฮพ1, ฮพ2 ๐, ๐ โ 0,1 , ๐๐ ๐ฅ = 2๐ฅ, ๐๐ ๐ฆ = 2๐ฆ
This PDF compresses space at higher values of x, ๐ฆ, dilates at lower
If space shrinks or grows, samples in it become denser or sparser
Visualizing the PDF in 2D
Rendering โ Importance Sampling 56
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ฮพ1, ฮพ2 ๐, ๐ โ 0,1 , ๐๐ ๐ฅ = 2๐ฅ, ๐๐ ๐ฆ = 2๐ฆ
Letโs transform a regular grid from polar to cartesian coordinates
Polar To Cartesian Coordinates
Rendering โ Importance Sampling 57
๐ = ๐ cos(๐)๐ = ๐ sin(๐)
๐
๐
Take 100k samples, transform and see in which square they end up
First Attempt to Learn the PDF
Rendering โ Importance Sampling 58
๐ = ๐ cos(๐)๐ = ๐ sin(๐)
Take 100k samples, transform and see in which square they end up
First Attempt to Learn the PDF
Rendering โ Importance Sampling 59
ฮพ1, ฮพ2 ๐ = ๐1 cos(2๐๐2), ๐ = ๐1 sin(2๐๐2)
Knowing the PDF
If we know the effect of a transformation ๐ on the PDF, we can
Use it in the Monte Carlo integral to weight our samples, or
Compensate to get a uniform sampling method after transformation
Rendering โ Importance Sampling 60
๐ผ๐๐๐ข๐ก (๐1, ๐2) ๐ถ๐๐๐ก๐๐ ๐๐๐ (๐ฅ, ๐ฆ)
๐๐๐๐๐ (r, ๐)
๐(๐, ๐)Scale +
compensate
Knowing the PDF
If we know the effect of a transformation ๐ on the PDF, we can
Use it in the Monte Carlo integral to weight our samples, or
Compensate to get a uniform sampling method after transformation
Rendering โ Importance Sampling 61
๐ผ๐๐๐ข๐ก (๐1, ๐2) ๐ถ๐๐๐ก๐๐ ๐๐๐ (๐ฅ, ๐ฆ)
๐๐๐๐๐ (r, ๐)
๐(๐, ๐)
Equal area!
Scale +
compensate
Computing the PDF after a Transformation
Assume a random variable ๐ด and a bijective transformation ๐ that yields another variable ๐ต = ๐ ๐ด
Bijectivity implies that ๐ = ๐(๐) must be either monotonically increasing or decreasing with ๐
This implies that there is a unique ๐ตi for every ๐ดi, and vice versa
In this case, the CDFs for the two variables fulfill ๐๐ต ๐(๐) = ๐๐ด(๐)
Rendering โ Importance Sampling 62
Computing the PDF after a Transformation
If ๐ = ๐(๐) and ๐ increases with ๐, we have: ๐๐๐ต(๐)
๐๐=
๐๐๐ด(๐)
๐๐
If ๐ decreases with ๐ (e.g., ๐ = โ๐), we have: โ๐๐๐ต(๐)
๐๐=
๐๐๐ด(๐)
๐๐
Since ๐๐ต is the non-negative derivative of ๐๐ต, we can rewrite as:
๐๐ต ๐๐๐
๐๐= ๐๐ด ๐ ,
๐๐ต ๐ =๐๐
๐๐
โ1
๐๐ด ๐
Rendering โ Importance Sampling 63
๐๐ ๐๐๐:๐๐๐ ๐ฅ
๐๐ฆ=๐๐ ๐ฅ ๐๐ฅ
๐๐ฆ
Computing the PDF after a Transformation
Letโs interpret ๐๐ต ๐ =๐๐
๐๐
โ1๐๐ด ๐
It is the probability density of ๐ด at ๐, multiplied by ๐๐
๐๐
โ1
๐๐
๐๐
โ1has two intuitive interpretations:
the change in sample density at point ๐ if we transform ๐ by ๐or, the reciprocal change in volume (space) for a volume element (hypercube) at point ๐ if we transform ๐ด by transformation ๐
Rendering โ Importance Sampling 64
Multidimensional Transformations
If we try to apply the above to the unit disk, we fail at ๐ฅ = ๐ sin ๐
We canโt evaluate ๐๐ฅ
๐๐
โ1: the transformation that produces one
target variable is dependent on both input variables and vice-versa
We cannot compute the change in the PDF between individual variables, we must take them all into account simultaneously
Itโs matrix time!Rendering โ Importance Sampling 65
Multidimensional Transformations
We write the set of ๐ values from a multidimensional variable ิฆ๐ด
as a vector ิฆ๐ and the ๐ outputs of transformation ๐ as a vector ๐:
ิฆ๐ =
๐1โฎ๐๐
, ๐ =๐1โฎ๐๐
=๐1( ิฆ๐)โฎ
๐๐( ิฆ๐)= ๐( ิฆ๐)
Instead of quantifying the change in volume incurred by ๐ ๐ ,๐๐ ๐
๐๐, our goal is now to quantify the change incurred by ๐ ิฆ๐
Rendering โ Importance Sampling 66
The Jacobian Matrix
For a transformation ๐ = ๐( ิฆ๐), we can define the Jacobian matrix that contains all ๐๐ , ๐๐ combinations of partial differentials
๐ฝ๐( ิฆ๐) =
๐๐1
๐๐1โฏ
๐๐1
๐๐๐
โฎ โฑ โฎ๐๐๐
๐๐1โฏ
๐๐๐
๐๐๐
If we consider ิฆ๐ดโs domain as a space with ๐ axes, ๐ฝ๐( ิฆ๐) gives the
change of the edges of a volume element from ิฆ๐ to ๐ = ๐( ิฆ๐)Rendering โ Importance Sampling 67
The Jacobian Matrix, Visualized
Change in edges of a volume element (infinitesimal hypercube) at ิฆ๐
๐ฝ๐( ิฆ๐) =
๐๐1๐๐1
โฏ๐๐1๐๐๐
โฎ โฑ โฎ๐๐๐๐๐1
โฏ๐๐๐๐๐๐
Rendering โ Importance Sampling 68
๐ิฆ๐10
๐๐1๐๐1๐๐2๐๐1
01
๐๐1๐๐2๐๐2๐๐2
The Jacobian
The columns of a square matrix can be interpreted as the natural
base vectors of a space
10โฎ0
,
01โฎ0
if they were transformed by it
The determinant . of a matrix yields the volume of a parallelepiped spanned by these vectors[3]
๐ฝ๐ , the Jacobian of ๐, gives the change in volume at ิฆ๐ due to ๐
Rendering โ Importance Sampling 69
๐
๐ฑ๐ป ๐
Computing the PDF of a Transformation
Letโs try polar coordinates again: ๐ฅ๐ฆ = ๐
๐๐
=๐ sin ๐๐ cos ๐
๐๐๐๐
๐๐๐
= ๐ฝ๐ =
๐๐ฅ
๐๐
๐๐ฅ
๐๐๐๐ฆ
๐๐
๐๐ฆ
๐๐
=cos ๐ โ๐ sin ๐sin ๐ ๐ cos ๐
= r
๐ ๐ฅ, ๐ฆ =๐(๐,๐)
๐, or ๐ ๐, ๐ = ๐ ๐ ๐ฅ, ๐ฆ , which tells us: the change in
probability density from (๐, ๐) to ๐ฅ, ๐ฆ is inverse proportional to ๐
Rendering โ Importance Sampling 70
Sampling Joint PDFs Correctly
For independent variables, the joint PDF ๐(๐ฅ, ๐ฆ, โฆ ) is ๐๐ ๐ฅ ๐๐ ๐ฆ โฆ
In general, this is an assumption that we should not rely on
Furthermore, after a transformation, only the joint PDF is known
The proper way to sample multiple variables ๐, ๐ is to compute
the marginal density function ๐๐ ๐ฅ of one
the conditional density function ๐๐ ๐ฆ|๐ฅ of the other
Rendering โ Importance Sampling 71
Marginal and Conditional Density Function
Assume we have obtained the joint PDF ๐ ๐ฅ, ๐ฆ of variables ๐, ๐with ranges [๐๐, ๐๐) and [๐๐, ๐๐)
In a 2D domain with ๐, ๐ we can think of ๐๐ ๐ฅ as the average density of ๐ ๐ฅ, ๐ฆ at a given ๐ฅ over all possible values ๐ฆ
We can obtain the marginal density function for one of them by
integrating out all the others, e.g.: ๐๐ ๐ฅ = โซ๐๐๐๐ ๐ ๐ฅ, ๐ฆ ๐๐ฆ
We can then find ๐ ๐ฆ|๐ฅ =๐(๐ฅ,๐ฆ)
๐๐(๐ฅ)
Rendering โ Importance Sampling 72
Adding More Variables
What to do for multiple variables, e.g. ๐, ๐ and ๐?
Find first marginal density ๐๐ ๐ฅ = โซ๐๐๐๐โซ๐๐๐๐๐ ๐ฅ, ๐ฆ, ๐ง ๐๐ฆ ๐๐ง
Find first conditional density ๐๐ ๐ฆ, ๐ง|๐ฅ =๐ ๐ฅ,๐ฆ,๐ง
๐๐ ๐ฅ
Find second marginal density ๐๐ ๐ฆ|๐ฅ = โซ๐๐๐๐๐ ๐ฅ, ๐ฆ, ๐ง ๐๐ง
Find second conditional density ๐๐ ๐ง|๐ฅ, ๐ฆ =๐ ๐ฆ,๐ง|๐ฅ
๐๐ ๐ฆ|๐ฅ
Integrate + invert first marginal, first and second conditional densities
Sample each of them
Extend ad libitum to even more variables
Rendering โ Importance Sampling 73
Sampling the Unit Disk: The Formal Solution
We know the proportionality constant is ๐ (area of sampled disk)
Since we want uniform sampling and sample probabilities should
integrate to 1, the target PDF in cartesian coordinates is ๐ ๐ฅ, ๐ฆ =1
๐
๐ฝ๐ told us that ๐ ๐, ๐ = ๐ ๐ ๐ฅ, ๐ฆ , so we want ๐ ๐, ๐ =๐
๐
๐๐ ๐ = โซ02๐๐ ๐, ๐ ๐๐ = 2๐ and ๐ ๐|๐ =
๐(๐,๐)
๐๐ (๐)=
1
2๐
Rendering โ Importance Sampling 74
Sampling the Unit Disk: The Formal Solution
If we create samples in polar coordinates for these PDFs, we will get the uniform distribution in (๐ฅ, ๐ฆ) after applying transformation ๐
Rendering โ Importance Sampling 75
๐
๐
Sampling the Unit Disk: The Formal Solution
Integrate marginal and conditional PDFs andinvertโwe get the same solution as before:
๐ = P๐ โ1 ๐1 = ๐1
๐ = ๐ฮโ1 ๐2 = 2๐๐2
๐ ๐|๐ is constant: no matter what radius we are looking at, all positions on a ring of that radius (angle) should be equally likely
Final integral: ๐ ๐บ๐ต๐ก๐๐ก๐๐ =๐
๐ฯ๐=1๐ ๐ ๐บ๐ต(๐ ๐ ๐ ๐๐ ฮ๐ , ๐ ๐ ๐๐๐ ฮ๐)
Rendering โ Importance Sampling 76
Todayโs Roadmap
Rendering โ Importance Sampling 77
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Importance
Sampling Unlocked!
Sampling the Unit Disk 2:
Crossing Domains
Moving on to the Hemisphere
This took as a while, but we have seen all the formal procedures
We only need to switch from integrating planar area to points ๐on hemisphere surface (i.e., vectors ๐ฅ, ๐ฆ, ๐ง with length 1)
Use spherical coordinates and bijective ๐ from (๐, ๐, ๐) to ๐ฅ, ๐ฆ, ๐ง :๐ฅ = ๐ sin ๐ cos๐๐ฆ = ๐ sin ๐ sin๐๐ง = ๐ cos ๐
Rendering โ Importance Sampling 78
Deriving Integration Over Hemisphere
Each direction ๐ represents an infinitesimal surface area portion ๐๐
How do we integrate a function ๐(๐) with differential ๐๐?
Integration over points on hemisphere surface ๐, w.r.t. (๐, ๐)
Rendering โ Importance Sampling 79
๐
๐
๐๐๐
๐
Deriving Integration Over Hemisphere
We assume a planar surface with an upright facing normal ๐
We use the integral intervals ๐ โ 0,๐
2, ๐ โ [0, 2๐)
I.e., a curve from perpendicular to parallel for ๐, a ring for ๐
Rendering โ Importance Sampling 80
2๐
๐
2
๐
Deriving Integration Over Hemisphere
We can split the surface along ๐ into ribbons of width ฮ๐ โ ๐๐
The upper edge of the ribbon is slightly shorter than the lower
If we keep adding more and more ribbons, this difference vanishes
Rendering โ Importance Sampling 81
ฮ๐
Deriving Integration Over Hemisphere
As a ribbonโs width goes to ๐๐, its area becomes its length times ๐๐
We can find this length by projecting the ribbon to the ground
Using trigonometry, we find the length of a ribbon is 2๐sin ๐
Rendering โ Importance Sampling 82
Deriving Integration Over Hemisphere
As a ribbonโs width goes to ๐๐, its area becomes its length times ๐๐
We can find this length by projecting the ribbon to the ground
Using trigonometry, we find the length of a ribbon is 2๐sin ๐
Rendering โ Importance Sampling 83
sin ๐๐
๐
The length of a ribbon spans the entire interval ๐ โ [0, 2๐)
Convert the length to an integral over ๐๐: 2๐sin ๐ = โซ02๐sin ๐ ๐๐
The final integral: โซฮฉ๐ ๐ ๐๐ = โซ0
๐
2 โซ02๐๐(๐) sin ๐ ๐๐ ๐๐
Deriving Integration Over Hemisphere
Rendering โ Importance Sampling 84
๐
๐
๐๐๐
๐
Deriving PDF for Hemisphere Sampling
Integral of ๐(๐) over area ฮ๐ = โซฮ๐ ๐(๐) ๐๐
Integral of ๐(๐) w.r.t. (๐๐, ๐๐) = โซฮ๐ โซฮ๐ ๐ ๐ sin ๐ ๐๐ ๐๐
Integration domain and ๐ ๐ are identical, thus: ๐๐ = sin ๐ ๐๐ ๐๐
๐ โ ๐, ๐ is bijective, we have ๐ ๐, ๐ d๐ ๐๐ = ๐ ๐ ๐๐ and:
๐ ๐, ๐ = sin ๐ ๐ ๐
Rendering โ Importance Sampling 85
ฮ๐ฮ๐
Deriving PDF for Hemisphere Sampling, the Formal Way
Target distribution in ๐, which is (๐ฅ, ๐ฆ, ๐ง) with x2 + ๐ฆ2 + ๐ง2 = 1
The transformation ๐ from (๐, ๐, ๐) to ๐ฅ, ๐ฆ, ๐ง :๐ฅ = ๐ sin ๐ cos๐๐ฆ = ๐ sin ๐ sin๐๐ง = ๐ cos ๐
The Jacobian of the transformation ๐ gives ๐ฝ๐ = ๐2 sin ๐
๐ = 1, so we have ๐ 1, ๐, ๐ = sin ๐ ๐(๐ฅ, ๐ฆ, ๐ง) = sin ๐ ๐(๐)
Rendering โ Importance Sampling 86
Uniformly Sampling the Unit Hemisphere
The domain, i.e., the unit hemisphere surface area, is 2๐.
Uniformly sampling the domain over ๐ implies ๐ ๐ =1
2๐
Hence, since ๐ 1, ๐, ๐ = sin ๐ ๐ ๐ , we want ๐ ๐, ๐ =sin ๐
2๐
Marginal density ๐ฮ(๐): โซ02๐๐ ๐, ๐ ๐๐ = sin ๐
Conditional density ๐ ๐|๐ :๐ ๐,๐
๐ฮ(๐)=
1
2๐Rendering โ Importance Sampling 87
Uniformly Sampling the Unit Hemisphere โ Complete
Antiderivative of ๐ฮ(๐): โซ sin ๐ ๐๐ = 1 โ cos ๐ (added constant 1)
Antiderivative of ๐ ๐|๐ : โซ1
2๐๐๐ =
๐
2๐
Invert them to get ๐ = cosโ1 ๐1 (cos is symmetric), ๐ = 2๐๐2
Apply transformation ๐ on (๐, ๐) to obtain uniformly distributed ๐
Finally done!Rendering โ Importance Sampling 88
Todayโs Roadmap
Rendering โ Importance Sampling 89
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Importance
Sampling Unlocked!
Sampling the Unit Disk 2:
Crossing Domains
Importance Sampling the Diffuse BRDF
Letโs look once more at the reflected light in the rendering equation
When we bounce at a point ๐ฅ, we already know quite a bit:
If we use a diffuse BRDF, then ๐ ๐ฅ, ๐ โ ๐ฃ is a constant factor๐
๐
We can predict the cosine termโit depends on our choice of ๐
The tricky part, the big unknown, is the ๐ฟ ๐ฅ โ ๐
Which directions will indirect light come from?
Rendering โ Importance Sampling 90
เถฑฮฉ
๐๐ ๐ฅ, ๐ โ ๐ฃ ๐ฟ ๐ฅ โ ๐ cos ๐๐ ๐๐
๐(๐ฅ)
If we donโt know anything about ๐ฟ, letโs just assume a constant k
๐
๐and ๐ are constant, so clearly,
๐
๐๐ cos ๐๐ โ cos ๐๐
With these assumptions, theintegrand function is governedentirely by the term ๐๐๐ ๐ฝ !
Importance Sampling the Diffuse BRDF
Rendering โ Importance Sampling 91
เถฑฮฉ
๐
๐๐ cos ๐๐ ๐๐
๐
Importance Sampling the Diffuse BRDF
We know that the ideal distribution ๐(๐ฅ) for importance sampling a function ๐ ๐ฅ is the one that minimizes variance, i.e., โ ๐ ๐ฅ itself
With the assumption of constant light from all directions, ourintegrand ๐ ๐ฅ was simplified to something proportional to cos ๐
Idea: Importance-sample hemispheresaround hit points with diffuse materialswith distribution ๐ ๐ โ cos ๐๐
Rendering โ Importance Sampling 92
๐ ๐
Uniform
hemisphere sampling
Cosine-weighted
hemisphere sampling
Cosine-Weighted Hemisphere Sampling?
In the first half, we saw how you can apply the inversion method for sampling arbitrary distributions
In the second half, we were all about making sure that we can reach our target distribution when we move from one domain to another
Cosine-weighted hemisphere sampling is a combination of the two
We have gone through all the necessary steps. Try to solve this formally with the inversion method as an exercise!
Rendering โ Importance Sampling 93
Cosine-Weighted Hemisphere Sampling!
Malleyโs method: uniformly pick ๐ฅ, ๐ฆ samples on the unit disk
Project them to the hemisphere surface ๐ง = 1 โ ๐ฅ2 โ ๐ฆ2
๐ ๐ =cos ๐
๐
Done! Your samples are nowdistributed with ๐ ๐ โ cos ๐!(Why? And why does this work? Try to find your own proof!)
Rendering โ Importance Sampling 94
Importance Sampling the Diffuse BRDF
Rendering โ Importance Sampling 95
AO, 64 samples, uniform hemisphere sampling AO, 64 samples, diffuse BRDF importance sampling
More Importance Sampling
The impact will be much greater when we add non-diffuse materials
BRDF functions canbe rather complexโฆ
โฆbut can often benicely approximated
You will want to sample with distributions more complex than cos ๐
Rendering โ Importance Sampling 96
Importance Sampling the Full Rendering Equation
As you can imagine, this is a much more complex task
In fact, an enormous amount of research in rendering is actively pursuing better and better ways to make this happen
Other sophisticated methods, like multiple importance sampling(MIS), can be of great help here!
We will hear more about MIS next timeโฆ
Rendering โ Importance Sampling 97
Importance Sampling Summary
If we do Monte Carlo integration of ๐(๐ฅ) , itโs best to use a sample distribution ๐(๐ฅ) that closely mimics ๐(๐ฅ)
For a desired ๐ ๐ฅ โ ๐(๐ฅ), we can use the inversion method to getthe methods for generating samples and probability densities
If you cannot turn ๐(๐ฅ) into a valid PDF, try to find a close match
When we transform samples between domains, we have to makesure they have the desired distribution in the target domain!
Rendering โ Importance Sampling 98
Todayโs Roadmap
Rendering โ Importance Sampling 99
What exactly are CDFs and PDFs?
What is the inversion method?
How to sample arbitrary functions?
Whatโs the fastest way to cosine-
weighted hemisphere sampling?
The Inversion
Method
Sampling the
Unit Disk
Required
Background
(CDF, PDF)
Importance Sampling
for the Diffuse BRDF
Sampling the
Hemisphere
Importance
Sampling Unlocked!
Sampling the Unit Disk 2:
Crossing Domains
References and Further Reading
Slide set based mostly on chapter 13 of Physically Based Rendering: From Theory to Implementation
[1] Steven Strogatz, Infinite Powers: How Calculus Reveals the Secrets of the Universe
[2] Video, Why โprobability of 0โ does not mean โimpossibleโ | Probabilities of probabilities, part 2: https://www.youtube.com/watch?v=ZA4JkHKZM50
[3] Video, The determinant | Essence of linear algebra, chapter 6: https://www.youtube.com/watch?v=Ip3X9LOh2dk
[4] SIGGRAPH 2012 Course: Advanced (Quasi-) Monte Carlo Methods for Image Synthesis, https://sites.google.com/site/qmcrendering/
[5] Wikipedia, Volume Element, https://en.wikipedia.org/wiki/Volume_element
Rendering โ Importance Sampling 100