Upload
elizabeth-fisher
View
216
Download
0
Tags:
Embed Size (px)
Citation preview
Monte Carlo I
Previous lecture Analytical illumination formula
This lecture Numerical evaluation of illumination Review random variables and probability Monte Carlo integration Sampling from distributions Sampling from shapes Variance and efficiency
Lighting and Soft Shadows
Challenges
Visibility and blockers
Varying light distribution
Complex source geometry
2
( ) ( , )cosi
H
E x L x dω θ ω=∫
Source: Agrawala. Ramamoorthi, Heirich, Moll, 2000
Penumbras and Umbras
Monte Carlo Lighting
1 eye ray per pixel1 shadow ray per eye
ray
Fixed Random
Monte Carlo Algorithms
Advantages Easy to implement Easy to think about (but be careful of statistical bias) Robust when used with complex integrands and
domains (shapes, lights, …) Efficient for high dimensional integrals Efficient solution method for a few selected points
Disadvantages Noisy Slow (many samples needed for convergence)
Random Variables
is chosen by some random process
probability distribution (density) function
X
~ ( )X p x
Discrete Probability Distributions
Discrete events Xi with probability pi
Cumulative PDF (distribution)
Construction of samples
To randomly select an event,
Select Xi if
0ip ≥1
1n
ii
p=
=∑
1i iP U P− < ≤
ip
1
j
j ii
P p=
=∑
Uniform random variable
U
1
0
3X
iP
Continuous Probability Distributions
PDF (density)
CDF (distribution)1
0
( ) Pr( )P x X x= <
Pr( ) ( )
( ) ( )
X p x dx
P P
β
α
α β
β α
≤ ≤ =
= −
∫
( )p x
10Uniform
( ) 0p x ≥
0
( ) ( )x
P x p x dx=∫(1) 1P =
( )P x
Sampling Continuous Distributions
Cumulative probability distribution function
Construction of samplesSolve for X=P-1(U)
Must know:1. The integral of p(x)2. The inverse function P-1(x)
U
X
1
0
( ) Pr( )P x X x= <
Example: Power Function
Assume( ) ( 1) np x n x= +
11 1
0 0
1
1 1
nn x
x dxn n
+
= =+ +∫
1( ) nP x x +=
1 1~ ( ) ( ) nX p x X P U U− +⇒ = =
1 2 1max( , , , , )n nY U U U U += L1
1
1
Pr( ) Pr( )n
n
i
Y x U x x+
+
=
< = < =∏
Trick
Sampling a Circle12 1 1 2 2
2
00 0 0 0 0
2
rA r dr d r dr d
π ππθ θ θ π
⎛ ⎞= = = =⎜ ⎟
⎝ ⎠∫∫ ∫ ∫
( , ) ( ) ( )p r p r pθ θ=
2
( ) 2
( )
p r r
P 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
1
2
2 U
r U
θ π=
=1
2
2 U
r U
θ π=
=
RIGHT Equi-ArealWRONG Equi-Areal
Rejection Methods
Algorithm
Pick U1 and U2
Accept U1 if U2 < f(U1)
Wasteful?
1
0
( )
( )
y f x
I f x dx
dx dy<
=
=
∫
∫∫ ( )y f x=
Efficiency = Area / Area of rectangle
Sampling a Circle: Rejection
May be used to pick random 2D directions
Circle techniques may also be applied to the sphere
do {
X=1-2*U1
Y=1-2*U2
}
while(X2 + Y2 > 1)
Monte Carlo Integration
Definite integral
Expectation of f
Random variables
Estimator
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 =
= ∑
Unbiased Estimator
1
1 1
1
1 0
1
1 0
1
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
Over Arbitrary Domains
∫=b
a
dxxfI )( abxp U
b
a −==
1)(
11
)()( =−
==∫b
a
b
a abxpxP∫−=
b
a
dxxpxfabI )()()(
)()( fEabI −=
fabI )( −≈
)(1
)(1
i
N
i
XfN
abI ∑=
−≈ a b
ab −1
Non-Uniform Distributions
∫=b
a
dxxfI )(
∫=b
a
dxxpxp
xfI )(
)(
)(
)(
)()(
xp
xfxg =
∫=b
a
dxxpxgI )()(
)(gEI =
∑=
≈N
i
iXgN
I1
)(1
Direct Lighting – Directional Sampling
2
( ) ( , ) cosH
E x L x dω θ ω=∫
*( ( , ), ) cos 2i i i iY L x x ω ω θ π= −
*( , )x x ωRay intersectionA′
ω
*x
x
θ Sample uniformly byΩω
Direct Lighting – Area Sampling
22
cos cos( ) ( , ) cos ( , ) ( , )o
AH
E x L x d L x V x x dAx x
θ θω θ ω ω′
′′ ′ ′ ′= =
′−∫ ∫
2
cos cos( , ) ( , ) i i
i o i i i
i
Y L x V x x Ax x
θ θω′
′ ′ ′=′−x
x xω′ ′= −Ray direction
Sample uniformly byA′x′
0( , )
1
visibleV x x
visible
¬⎧′ =⎨⎩
A′
ω′
x′
θθ′
Examples
4 eye rays per pixel1 shadow ray per eye ray
Fixed Random
Examples
4 eye rays per pixel16 shadow rays per eye ray
Uniform grid Stratified random
Examples
4 eye rays per pixel64 shadow rays per eye ray
Uniform grid Stratified random
Examples
4 eye rays per pixel100 shadow rays per eye ray
Uniform grid Stratified random
Examples
4 eye rays per pixel16 shadow rays per eye ray
64 eye rays per pixel1 shadow ray per eye ray
Variance
Definition
Properties
Variance decreases with sample size
2
2 2
2 2
[ ] [( [ ]) ]
[ 2 [ ] [ ] ]
[ ] [ ]
V Y E Y E Y
E Y YE Y E Y
E Y E Y
≡ −
= − +
= −
[ ] [ ]i ii i
V Y V Y=∑ ∑2[ ] [ ]V aY a V Y=
21 1
1 1 1[ ] [ ] [ ]
N N
i ii i
V Y V Y V YN N N= =
= =∑ ∑
Direct Lighting – Directional Sampling
2
( ) ( , ) cosH
E x L x dω θ ω=∫
*( ( , ), ) cos 2i i i iY L x x ω ω θ π= −
*( ( , ), )i i iY L x x ω ω π= −
*( , )x x ωRay intersection
A′
ω
*x
x
θSample uniformly byΩω
Sample uniformly byΩ%ω
Sampling Projected Solid Angle
Generate cosine weighted distribution
Examples
Projected solid angle
4 eye rays per pixel100 shadow rays
Area
4 eye rays per pixel100 shadow rays
Variance Reduction
Efficiency measure
Techniques Importance sampling Sampling patterns: stratified, …
1Efficiency
Variance Cost∝
•
Sampling a Triangle
121 1 1
0 0 00
(1 ) 1(1 )
2 2
u uA dv du u du
− −= = − =− =∫∫ ∫
( , ) 2p u v =
0
0
1
u
v
u v
≥≥+ ≤
u
v
1u v+ =
( ,1 )u u−
)(
),()|(
vp
vupvup ≡
Sampling a Triangle
Here u and v are not independent!
Conditional probability
( , ) 2p u v =
00 0 00 0
0 0
1( | ) ( | )
(1 ) (1 )o ov v v
P v u p v u dv dvu u
= = =− −∫ ∫
1( | )
(1 )p v u
u=
−
0 20 00
( ) 2(1 ) (1 )u
P u u du u= − = −∫
1
0
( ) 2 2(1 )u
p u dv u−
= = −∫0 11u U= −
0 1 2v U U=
∫≡ dvvupup ),()(