Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
CS348b Lecture 6
Monte Carlo 1: Integration
Previous lecture: Analytical illumination formula
This lecture: Monte Carlo Integration
■ Review random variables and probability
■ Sampling from distributions
■ Sampling from shapes
■ Numerical calculation of illumination
Pat Hanrahan / Matt Pharr, Spring 2019
Irradiance from the Environment
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
2
( ) ( , )cosiH
E x L x dω θ ω= ∫
ω ω θ ωΦ =2 ( , ) ( , )cosi id x L x dA d
( , ) ( , )cosidE x L x dω ω θ ω=
Light meter
ω( , )iL x
dA
θdω
Irradiance from a Uniform Area Source
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
2
( ) cos
cosH
E x L d
L d
L
θ ω
θ ωΩ
=
=
= Ω
∫
∫!
A
Ω!
Ω
Direct Illumination
Uniform Triangle Light Source
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
1 1
n n
i i ii iA γ
= =
= •∑ ∑ N N! !
�iedge i
~N
~Ni
Penumbras and Umbras
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
CS348b Lecture 6
Lighting and Soft Shadows
Challenges
1 Occluders
- Complex geometry
- Number of occluders
2 Non-uniform light sources
Pat Hanrahan / Matt Pharr, Spring 2019
2
( ) ( , )cosiH
E x L x dω θ ω= ∫
Source: Agrawala. Ramamoorthi, Heirich, Moll, 2000
Monte Carlo Illumination Calculation
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
1 shadow ray per eye ray
Center Random
CS348b Lecture 6
Monte Carlo Algorithms
Advantages
■ Easy to implement
■ Easy to think about (but be careful of subtleties)
■ Robust when used with complex integrands (lights, BRDFs) and domains (shapes)
■ Efficient for high dimensional integrals
■ Efficient when only need solution at a few points
Disadvantages
■ Noisy
■ Slow (many samples needed for convergence)
Pat Hanrahan / Matt Pharr, Spring 2019
CS348b Lecture 6
Random Variables
is a random variable
A random variable takes on different values
(represents a distribution of potential values)
probability distribution function (PDF)
Pat Hanrahan / Matt Pharr, Spring 2019
X
~ ( )X p x
CS348b Lecture 6
Discrete Probability Distributions
Discrete values
with probability
Pat Hanrahan / Matt Pharr, Spring 2019
0ip ≥
11
n
iip
=
=∑
ip
ix
ipix
CS348b Lecture 6
Discrete Probability Distributions
Cumulative PDF
Pat Hanrahan / Matt Pharr, Spring 2019
=
=∑1
j
j ii
P p
1
0
jP
≤ ≤0 1iP
=1nP
jP
CS348b Lecture 6
Discrete Probability Distributions
Construction of samples
To randomly select an event,
Select if
Pat Hanrahan / Matt Pharr, Spring 2019
1i iP U P− < ≤
U
1
0
Uniform random variable
3x
ix
CS348b Lecture 6
Continuous Probability Distributions
CDF
Pat Hanrahan / Matt Pharr, Spring 2019
1
0
( ) Pr( )P x X x= <
Pr( ) ( )
( ) ( )
X p x dx
P P
β
α
α β
β α
≤ ≤ =
= −
∫
( )p x
10
Uniform
( ) 0p x ≥
0
( ) ( )x
P x p x dx= ∫(1) 1P =
( )P x
CS348b Lecture 6
Sampling Continuous Distributions
Cumulative probability distribution function
Construction of samples
Solve for
Must know the formula for:
1. The integral of
2. The inverse function
Pat Hanrahan / Matt Pharr, Spring 2019
U
X
1
0
( ) Pr( )P x X x= <
p(x)
P�1(x)
X = P�1(U)
Sampling a Circle
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
12 1 1 2 22
00 0 0 0 0
2rA r dr d r dr d
π ππ
θ θ θ π# $
= = = =% &' (
∫ ∫ ∫ ∫
( , ) ( ) ( )p r p r pθ θ=
2
( ) 2( )p r rP r r
=
=
12 Uθ π=
rdθ
dr
1( )21( )2
p
P
θπ
θ θπ
=
=
1( , ) ( , ) rp r dr d r dr d p rθ θ θ θπ π
= ⇒ =
2r U=
Sampling a Circle
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
1
2
2 Ur Uθ π=
=1
2
2 U
r U
θ π=
=
RIGHT = Equi-ArealWRONG ≠ Equi-Areal
classShape{public://ShapeInterface…virtual~Shape();virtualBounds3fObjectBound()const=0;virtualBounds3fWorldBound()const;virtualboolIntersect(constRay&ray,Float*tHit,SurfaceInteraction*isect,booltestAlphaTexture=true)const=0;…virtualFloatArea()const=0;…//Sampleapointonthesurfaceoftheshape//andreturnthePDFwithrespecttoareaonthesurface.virtualInteractionSample(constPoint2f&u,Float*pdf)const=0;virtualFloatPdf(constInteraction&)const{return1/Area();}..};
Rejection Sampling
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
Area of circle / Area of square
Efficiency?
do{
X=Uniform(-1,1)
Y=Uniform(-1,1)
}while(X*X+Y*Y>1);
Sampling 2D Directions
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
do{
X=Uniform(-1,1);
Y=Uniform(-1,1);
}while(X*X+Y*Y>1);
R=sqrt(X*X+Y*Y)
dx=X/R
dy=Y/R
Computing Area of a Circle
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
A=0
for(i=0;i<N;i++){
X=Uniform(-1,1);
Y=Uniform(-1,1);
if(X*X+Y*Y<1)
A+=1;
}
A=4*A/N
Definite integral
Expectation of
Random variables
Estimator
Monte Carlo Integration
1
0
( ) ( )I f f x dx≡ ∫1
0
[ ] ( ) ( )E f f x p x dx≡ ∫
~ ( )iX p x( )i iY f X=
1
1 N
N ii
F YN =
= ∑
f
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
Unbiased Estimator
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
1
1 11
1 01
1 01
0
1[ ] [ ]
1 1[ ] [ ( )]
1 ( ) ( )
1 ( )
( )
N
N ii
N N
i ii i
N
i
N
i
E F E YN
E Y E f XN N
f x p x dxN
f x dxN
f x dx
=
= =
=
=
=
= =
=
=
=
∑
∑ ∑
∑∫
∑∫
∫
[ ] ( )NE F I f=
Assume uniform probability distribution for now
[ ] [ ]i ii i
E Y E Y=∑ ∑[ ] [ ]E aY aE Y=
Properties
Direct Lighting: Hemispherical Integral
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
dA
θdω
2
( ) ( , ) cosH
E x L x dω θ ω= ∫
ω( , )iL x
Direct Lighting: Solid Angle Sampling
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
2
( ) 1H
p dω ω =∫
Sample hemisphere uniformly
dA
θdω
ω( , )iL x
Direct Lighting: Solid Angle Sampling
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
Estimator
dA
θdω
ω( , )iL x
Direct Lighting: Hemisphere Sampling
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
Hemisphere
16 shadow rays
Direct Lighting: Area Integral
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
A!x!
x
θθ "
0 blocked( , )
1 visibleV x x
!" = #
$Radiance
Visibility
Integral
Direct Lighting: Area Integral
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
A!x!
x
θθ "
Direct Lighting: Area Sampling
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
A!x!
x
θθ "
Sample shape uniformly by area
Direct Lighting: Area Sampling
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
A!
ω"
x!
x
θθ " Estimator
Direct Lighting: Area Sampling
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
Area
16 shadow rays
Random Sampling Introduces Noise
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
1 shadow ray per eye ray
Center Random
Quality Improves with More Rays
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
16 shadow rays1 shadow ray
Area Area
Why is Area Better than Hemisphere?
CS348b Lecture 6 Pat Hanrahan / Matt Pharr, Spring 2019
Hemisphere
16 shadow rays
Area
16 shadow rays