Computer Graphics III – Monte Carlo integration Direct illumination
Jaroslav Křivánek, MFF UK Jaroslav.Krivanek@mff.cuni.cz
Computer Graphics III Monte Carlo integration Direct illumination - - PowerPoint PPT Presentation
Computer Graphics III Monte Carlo integration Direct illumination Jaroslav Kivnek, MFF UK Jaroslav.Krivanek@mff.cuni.cz Entire the lecture in 5 slides in out Reflection equation Total reflected radiance: integrate
Jaroslav Křivánek, MFF UK Jaroslav.Krivanek@mff.cuni.cz
◼ Total reflected radiance: integrate contributions of incident
𝑀out(𝜕out) = න
𝐼(𝐲)
𝑀in(𝜕in) ⋅ 𝑔
𝑠(𝜕in → 𝜕out) ⋅ cos 𝜄in d𝜕in
CG III (NPGR010) - J. Křivánek 2015
𝑀out 𝑀in
◼ Problems
❑ Discontinuous integrand
❑ Arbitrarily large integrand
❑ Complex geometry
CG III (NPGR010) - J. Křivánek 2015 4
Incoming radiance Lin(x,win) for a point
Images: Greg Ward
𝑀out(𝜕out) = න
𝐼(𝐲)
𝑀in(𝜕in) ⋅ 𝑔
𝑠(𝜕in → 𝜕out) ⋅ cos 𝜄in d𝜕in
◼ General tool for estimating definite integrals
𝐽 = න(𝐲)d𝐲 𝐽 = 1 𝑂
𝑙=1 𝑂 (𝜊𝑙)
𝑞(𝜊𝑙) ; 𝜊𝑙 ∝ 𝑞(𝐲)
𝐹[ 𝐽 ] = 𝐽
CG III (NPGR010) - J. Křivánek 2015 5
◼ Integral to be estimated: ◼ pdf for cosine-proportional sampling: ◼ MC estimator (formula to use in the renderer):
CG III (NPGR010) - J. Křivánek 2015 6
𝑞(𝜕in) = cos 𝜄in 𝜌 න
𝐼(𝐲)
𝑀in(𝜕in) 𝑔
𝑠(𝜕in → 𝜕out) cos 𝜄in d𝜕in
integrand(win) 𝑀out = 1 𝑂
𝑙=1 𝑂 integrand 𝜕in,𝑙
pdf 𝜕in,𝑙 = 𝜌 𝑂
𝑙=1 𝑂
𝑀in 𝜕in,𝑙 𝑔
𝑠(𝜕in,𝑙 → 𝜕out)
// input variables x...shaded point on a surface normal...surface normal at x
estimatedRadianceOut := Rgb(0,0,0); for k = 1...N [omegaInK, pdf] := generateRndDirection(); // evaluate integrand radianceInEst := getRadianceIn(x, omegaInK); brdf := evalBrdf(x, omegaInK, omegaOut); cosThetaIn := dot(normal, omegaInK); integrand := radianceInEst * brdf * cosThetaIn; // evaluate contribution to the outgoing radiance estimatedRadianceOut += integrand / pdf; end for estimatedRadianceOut /= N;
CG III (NPGR010) - J. Křivánek 2015 7
CG III (NPGR010) - J. Křivánek 2015 8
◼ General formula in 1D:
መ 𝐽 =
𝑙=1 𝑂
𝑥𝑙(𝑦𝑙)
CG III (NPGR010) - J. Křivánek 2015 11
◼ Quadrature rules differ by the choice of node point
❑
◼ The samples (i.e. the node points) are placed
CG III (NPGR010) - J. Křivánek 2015 12
◼ General formula for quadrature of a function of multiple
◼ Convergence speed of approximation error E for a d-
❑ E.g. in order to cut the error in half for a 3-dimensional
◼ Unusable in higher dimensions
❑ Dimensional explosion
መ 𝐽 =
𝑙1=1 𝑂
𝑙2=1 𝑂
. . .
𝑙𝑒=1 𝑂
𝑥𝑙1𝑥𝑙2. . . 𝑥𝑙𝑡𝑔(𝑦𝑙1, 𝑦𝑙2, . . . , 𝑦𝑙𝑒)
CG III (NPGR010) - J. Křivánek 2015 13
◼ Deterministic quadrature vs. Monte Carlo
❑ In 1D deterministic better than Monte Carlo ❑ In 2D roughly equivalent ❑ From 3D, MC will always perform better
◼ Remember, quadrature rules are NOT the Monte Carlo
CG III (NPGR010) - J. Křivánek 2015 14
◼ Atomic bomb development, Los Alamos 1940
◼ Further development and practical applications from the
CG III (NPGR010) - J. Křivánek 2015 16
◼ We simulate many random occurrences of the same type
❑ Neutrons – emission, absorption, collisions with hydrogen
❑ Behavior of computer networks, traffic simulation. ❑ Sociological and economical models – demography,
CG III (NPGR010) - J. Křivánek 2015 17
◼ Financial market simulations ◼ Traffic flow simulations ◼ Environmental sciences ◼ Particle physics ◼ Quantum field theory ◼ Astrophysics ◼ Molecular modeling ◼ Semiconductor devices ◼ Optimization problems ◼ Light transport calculations ◼ ...
CG III (NPGR010) - J. Křivánek 2015 18
CG III (NPGR010) - J. Křivánek 2015
Slide credit: Iwan Kawrakov
19
CG III (NPGR010) - J. Křivánek 2015
Slide credit: Iwan Kawrakov
20
CG III (NPGR010) - J. Křivánek 2015 21
◼
◼
❑
❑
◼
❑
❑
CG III (NPGR010) - J. Křivánek 2015 22
◼ Pros
❑ Simple implementation ❑ Robust solution for complex integrands and integration
❑ Effective for high-dimensional integrals
◼ Cons
❑ Relatively slow convergence – halving the standard error
❑ In rendering: images contain noise that disappears slowly
CG III (NPGR010) - J. Křivánek 2015 23
◼ X … random variable ◼ X assumes different values with different probability
❑ Given by the probability distribution D ❑ X D
CG III (NPGR010) - J. Křivánek 2015 25
◼ Finite set of values of xi ◼ Each assumed with prob. pi ◼ Cumulative distribution
CG III (NPGR010) - J. Křivánek 2015 26
i i
=
n i i
1
i
i
Probability mass function
=
i j j i i
1
n
i
i
Cumulative distribution func.
◼ Probability density function, pdf, p(x) ◼ In 1D:
CG III (NPGR010) - J. Křivánek 2015 27
D
b a
◼ Cumulative distribution function, cdf, P(x)
CG III (NPGR010) - J. Křivánek 2015 28
−
x
a a
CG III (NPGR010) - J. Křivánek 2015 29
CG III (NPGR010) - J. Křivánek 2015 30
Image: wikipedia
◼ Expected value ◼ Variance
❑ Properties of variance
D
(if Xi are independent)
CG III (NPGR010) - J. Křivánek 2015 31
◼ Y is a random variable ◼ Expected value of Y
CG III (NPGR010) - J. Křivánek 2015 32
𝐸
◼ General tool for estimating definite integrals
𝐽 = න(𝐲)d𝐲
𝐽 = 1 𝑂
𝑙=1 𝑂 (𝜊𝑙)
𝑞(𝜊𝑙) ; 𝜊𝑙 ∝ 𝑞(𝐲)
𝐹[ 𝐽 ] = 𝐽
CG III (NPGR010) - J. Křivánek 2015 34
prim
CG III (NPGR010) - J. Křivánek 2015 35
CG III (NPGR010) - J. Křivánek 2015 36
◼ Estimator is a random variable
❑ It is defined though a transformation of another random
◼ Estimate is a concrete realization (outcome) of the
◼ No need to worry: the above distinction is important for
CG III (NPGR010) - J. Křivánek 2015 37
◼ A general statistical estimator is called unbiased if –
◼ More precisely:
CG III (NPGR010) - J. Křivánek 2015 38
Estimated quantity (In our case, it is an integral, but in general it could be
random variable.) Estimator of the quantity Q (random variable)
CG III (NPGR010) - J. Křivánek 2015 39
prim
2 2 2 prim 2 prim 2 prim prim
(for an unbiased estimator)
CG III (NPGR010) - J. Křivánek 2015 40
◼ Consider N independent random variables Xk ◼ The estimator FN given be the formula below is called the
◼ The secondary estimator is unbiased.
CG III (NPGR010) - J. Křivánek 2015 41
𝐺𝑂 = 1 𝑂
𝑙=1 𝑂 𝑔 𝑌𝑙
𝑞 𝑌𝑙
𝑊 𝐺
𝑂
= 𝑊 1 𝑂
𝑙=1 𝑂 𝑔(𝑌𝑙)
𝑞(𝑌𝑙) = 1 𝑂2 ⋅ 𝑂 ⋅ 𝑊 𝑔(𝑌𝑙) 𝑞(𝑌𝑙) = 1 𝑂 𝑊 𝐺prim
CG III (NPGR010) - J. Křivánek 2015 42
◼ A general statistical estimator is called unbiased if –
◼ More precisely:
CG III (NPGR010) - J. Křivánek 2015 44
Estimated quantity (In our case, it is an integral, but in general it could be
random variable.) Estimator of the quantity Q (random variable)
◼ If
◼ Bias is the systematic error of the estimator:
CG III (NPGR010) - J. Křivánek 2015 45
◼ Consider a secondary estimator with N samples: ◼ Estimator FN is consistent if
CG III (NPGR010) - J. Křivánek 2015 46
2 1 N N N
◼ Sufficient condition for consistency of an estimator: ◼ Unbiasedness is not sufficient for consistency by itself (if
◼ But if the variance of a primary estimator finite, then the
CG III (NPGR010) - J. Křivánek 2015 47
◼ Unbiased
❑ Path tracing ❑ Bidirectional path tracing ❑ Metropolis light transport
◼ Biased & Consistent
❑ Progressive photon mapping
◼ Biased & not consistent
❑ Photon mapping ❑ Irradiance / radiance caching
CG III (NPGR010) - J. Křivánek 2015 48
◼ Definition ◼ Proposition
❑ Proof
CG III (NPGR010) - J. Křivánek 2015 49
2
2
◼ If the estimator F is unbiased, then
◼ Unbiased estimator of variance
CG III (NPGR010) - J. Křivánek 2015 50
CG III (NPGR010) - J. Křivánek 2015 51
◼ Efficiency of an unbiased estimator is given by:
CG III (NPGR010) - J. Křivánek 2015 52
◼ Integral to be estimated: ◼ pdf for uniform hemisphere sampling: ◼ MC estimator (formula to use in the renderer):
CG III (NPGR010) - J. Křivánek 2015 54
𝑀out = 1 𝑂
𝑙=1 𝑂 integrand 𝜕in,𝑙
pdf 𝜕in,𝑙 = 2𝜌 𝑂
𝑙=1 𝑂
𝑀in 𝜕in,𝑙 𝑔
𝑠(𝜕in,𝑙 → 𝜕out) cos 𝜄in,𝑙
𝑞(𝜕in) = 1 2𝜌 න
𝐼(𝐲)
𝑀in(𝜕in) 𝑔
𝑠(𝜕in → 𝜕out) cos 𝜄in d𝜕in
integrand(win)
◼ Integral to be estimated: ◼ pdf for cosine-proportional sampling: ◼ MC estimator (formula to use in the renderer):
CG III (NPGR010) - J. Křivánek 2015 55
𝑞(𝜕in) = cos 𝜄in 𝜌 න
𝐼(𝐲)
𝑀in(𝜕in) 𝑔
𝑠(𝜕in → 𝜕out) cos 𝜄in d𝜕in
integrand(win) 𝑀out = 1 𝑂
𝑙=1 𝑂 integrand 𝜕in,𝑙
pdf 𝜕in,𝑙 = 𝜌 𝑂
𝑙=1 𝑂
𝑀in 𝜕in,𝑙 𝑔
𝑠(𝜕in,𝑙 → 𝜕out)
CG III (NPGR010) - J. Křivánek 2015 56
◼ Reformulate the reflection integral (change of variables) ◼ PDF for uniform sampling of the surface area: ◼ Estimator
CG III (NPGR010) - J. Křivánek 2015 57
A H
2 e ) ( i i i i
x y x
=
N k k k k N
1 e
CG III (NPGR010) - J. Křivánek 2015 58
Light source area sampling Cosine-proportional sampling Images: Pat Hanrahan
CG III (NPGR010) - J. Křivánek 2015 59
CG III (NPGR010) - J. Křivánek 2015 60
1 sample per pixel 9 samples per pixel 36 samples per pixel
CG III (NPGR010) - J. Křivánek 2015 61
◼ Integral to be estimated ◼ Estimator based on uniform light source sampling
CG III (NPGR010) - J. Křivánek 2015 62
A r
=
N k k k k r k N
1