Computer Graphics III Monte Carlo integration Direct illumination - - PowerPoint PPT Presentation

computer graphics iii
SMART_READER_LITE
LIVE PREVIEW

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 Reflection equation = L ( ) L


slide-1
SLIDE 1

Computer Graphics III – Monte Carlo integration Direct illumination

Jaroslav Křivánek, MFF UK Jaroslav.Krivanek@mff.cuni.cz

slide-2
SLIDE 2

Entire the lecture in 5 slides

slide-3
SLIDE 3

Reflection equation

 →  =

) ( i i

  • i

i i

  • r

d cos ) ( ) ( ) (

x H r

f L L       di Lo(o) o n Li(i) i Lr(o)

upper hemisphere

  • ver x

CG III (NPGR010) - J. Křivánek 2015

slide-4
SLIDE 4

Rendering = Integration of functions

◼ Problems

❑ Discontinuous integrand

(visibility)

❑ Arbitrarily large integrand

values (e.g. light distribution in caustics, BRDFs of glossy surfaces)

❑ Complex geometry

CG III (NPGR010) - J. Křivánek 2015 4

→ =

) ( i i

  • i

i i

  • r

d cos ) ( ) ( ) (

x H r

f L L      

Incoming radiance Li(x,i) for a point

  • n the floor.

Images: Greg Ward

slide-5
SLIDE 5

Monte Carlo integration

◼ General tool for estimating definite integrals

1 f(x) 1 p(x) 2 3 4 5 6

= x x d ) ( f I ) ( ; ) ( ) ( 1

1

x p p f N I

i N i i i

 =

=

   Integral: Monte Carlo estimate I: Works “on average”: I I E = ] [

CG III (NPGR010) - J. Křivánek 2015 5

slide-6
SLIDE 6

◼ Integral to be estimated: ◼ PDF for cosine-proportional sampling: ◼ MC estimator (formula to use in the renderer):

Application of MC to reflection eq: Estimator of reflected radiance

CG III (NPGR010) - J. Křivánek 2015 6

( ) ( )

 

= =

→ = =

N k ,k r ,k N k ,k ,k N

f L N N F

1

  • i

i i 1 i i

) ( ) ( pdf integrand 1         

i i

cos ) ( = p

) ( i i

  • i

i i

d cos ) ( ) (

x H r

f L     

integrand(i)

slide-7
SLIDE 7

Variance => image noise

CG III (NPGR010) - J. Křivánek 2015 7

slide-8
SLIDE 8

… and now the slow way

slide-9
SLIDE 9

Digression: Numerical quadrature

slide-10
SLIDE 10

Quadrature formulas for numerical integration

◼ General formula in 1D:

f integrand (i.e. the integrated function) n quadrature order (i.e. number of integrand samples) xi node points (i.e. positions of the samples) f(xi) integrand values at node points wi quadrature weights

=

=

n i i i

x f w I

1

) ( ˆ

CG III (NPGR010) - J. Křivánek 2015 10

slide-11
SLIDE 11

Quadrature formulas for numerical integration

◼ Quadrature rules differ by the choice of node point

positions xi and the weights wi

E.g. rectangle rule, trapezoidal rule, Simpson’s method, Gauss quadrature, …

◼ The samples (i.e. the node points) are placed

deterministically

CG III (NPGR010) - J. Křivánek 2015 11

slide-12
SLIDE 12

Quadrature formulas in multiple dimensions

◼ General formula for quadrature of a function of multiple

variables:

◼ Convergence speed of approximation error E for an s-

dimensional integral is E = O(N-1/s)

❑ E.g. in order to cut the error in half for a 3-dimensional

integral, we need 23 = 8 – times more samples

◼ Unusable in higher dimensions

❑ Dimensional explosion

 

= = =

=

n i n i n i i i i i i i

s s s

x x x f w w w I

1 1 1

1 2 2 1 2 1

) ,..., , ( ... ... ˆ

CG III (NPGR010) - J. Křivánek 2015 12

slide-13
SLIDE 13

Quadrature formulas in multiple dimensions

◼ 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

method

CG III (NPGR010) - J. Křivánek 2015 13

slide-14
SLIDE 14

Monte Carlo

slide-15
SLIDE 15

History of the Monte Carlo method

◼ Atomic bomb development, Los Alamos 1940

John von Neumann, Stanislav Ulam, Nicholas Metropolis

◼ Further development and practical applications from the

early 50’s

CG III (NPGR010) - J. Křivánek 2015 15

slide-16
SLIDE 16

Monte Carlo method

◼ We simulate many random occurrences of the same type

  • f events, e.g.:

❑ Neutrons – emission, absorption, collisions with hydrogen

nuclei

❑ Behavior of computer networks, traffic simulation. ❑ Sociological and economical models – demography,

inflation, insurance, etc.

CG III (NPGR010) - J. Křivánek 2015 16

slide-17
SLIDE 17

Monte Carlo – applications

◼ 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 17

slide-18
SLIDE 18

CG III (NPGR010) - J. Křivánek 2015

Slide credit: Iwan Kawrakov

18

slide-19
SLIDE 19

CG III (NPGR010) - J. Křivánek 2015

Slide credit: Iwan Kawrakov

19

slide-20
SLIDE 20

Variance => image noise

CG III (NPGR010) - J. Křivánek 2015 20

slide-21
SLIDE 21

Monte Carlo integration

Samples are placed randomly (or pseudo-randomly)

Convergence of standard error: std. dev. = O(N-1/2)

Convergence speed independent of dimension

Faster than classic quadrature rules for 3 and more dimensions

Special methods for placing samples exist

Quasi-Monte Carlo

Faster asymptotic convergence than MC for “smooth” functions

CG III (NPGR010) - J. Křivánek 2015 21

slide-22
SLIDE 22

Monte Carlo integration

◼ Pros

❑ Simple implementation ❑ Robust solution for complex integrands and integration

domains

❑ Effective for high-dimensional integrals

◼ Cons

❑ Relatively slow convergence – halving the standard error

requires four times as many samples

❑ In rendering: images contain noise that disappears slowly

CG III (NPGR010) - J. Křivánek 2015 22

slide-23
SLIDE 23

Review – Random variables

slide-24
SLIDE 24

Random variable

◼ 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 24

slide-25
SLIDE 25

Discrete random variable

◼ Finite set of values of xi ◼ Each assumed with prob. pi ◼ Cumulative distribution

function

CG III (NPGR010) - J. Křivánek 2015 25

) Pr(  = 

i i

x X p

=

=

n i i

p

1

1

i

p

i

x

Probability mass function

( ) 

=

=  

i j j i i

p x X P

1

Pr

1 =

n

P

i

P

i

x

Cumulative distribution func.

1

slide-26
SLIDE 26

Continuous random variable

◼ Probability density function, pdf, p(x) ◼ In 1D:

CG III (NPGR010) - J. Křivánek 2015 26

( )

x x p D X

D

d ) ( Pr

= 

( ) 

=  

b a

t t p b X a d ) ( Pr

slide-27
SLIDE 27

Continuous random variable

◼ Cumulative distribution function, cdf, P(x)

V 1D:

CG III (NPGR010) - J. Křivánek 2015 27

( )  

=  

x

t t p x X x P d ) ( Pr ) (

( )

! d ) ( Pr = = =

a a

t t p a X

slide-28
SLIDE 28

Continuous random variable

CG III (NPGR010) - J. Křivánek 2015 28

Example: Uniform distribution Probability density function (pdf) Cumulative distribution function (cdf)

slide-29
SLIDE 29

Continuous random variable

CG III (NPGR010) - J. Křivánek 2015 29

Image: wikipedia

Gaussian (normal) distribution Probability density function (pdf) Cumulative distribution function (cdf)

slide-30
SLIDE 30

Expected value and variance

◼ Expected value ◼ Variance

❑ Properties of variance

  

=

D

p X E x x x d ) (

(if Xi are independent)

CG III (NPGR010) - J. Křivánek 2015 30

slide-31
SLIDE 31

Transformation of a random variable

◼ Y is a random variable ◼ Expected value of Y

CG III (NPGR010) - J. Křivánek 2015 31

𝑍 = 𝑕(𝑌) 𝐹[𝑍] = න

𝐸

𝑕 𝐲 𝑞 𝐲 𝑒𝐲

slide-32
SLIDE 32

Monte Carlo integration

slide-33
SLIDE 33

Monte Carlo integration

◼ General tool for estimating definite integrals

1 f(x) 1 p(x) 2 3 4 5 6

= x x d ) ( f I ) ( ; ) ( ) ( 1

1

x p p f N I

i N i i i

 =

=

   Integral: Monte Carlo estimate I: Works “on average”: I I E = ] [

CG III (NPGR010) - J. Křivánek 2015 33

slide-34
SLIDE 34

( )

= x x f I d

Integral to be estimated: Let X be a random variable from the distribution with the pdf p(x), then the random variable Fprim given by the transformation f(X)/p(X) is called the primary estimator of the above integral.

) ( ) (

prim

X p X f F =

CG III (NPGR010) - J. Křivánek 2015 34

Primary estimator of an integral

slide-35
SLIDE 35

Primary estimator of an integral

X f(x) f(X) 1

CG III (NPGR010) - J. Křivánek 2015 35

slide-36
SLIDE 36

Estimator vs. estimate

◼ Estimator is a random variable

❑ It is defined though a transformation of another random

variable

◼ Estimate is a concrete realization (outcome) of the

estimator

◼ No need to worry: the above distinction is important for

proving theorems but less important in practice

CG III (NPGR010) - J. Křivánek 2015 36

slide-37
SLIDE 37

Unbiased estimator

◼ A general statistical estimator is called unbiased if –

“on average” – it yields the correct value of an estimated quantity Q (without systematic error).

◼ More precisely:

CG III (NPGR010) - J. Křivánek 2015 37

 

Q F E =

Estimated quantity (In our case, it is an integral, but in general it could be

  • anything. It is a number, not a

random variable.) Estimator of the quantity Q (random variable)

slide-38
SLIDE 38

Unbiased estimator

The primary estimator Fprim is an unbiased estimator of the integral I. Proof:

CG III (NPGR010) - J. Křivánek 2015 38

 

( ) ( )

I x x p x p x f F E = = 

d ) (

prim

slide-39
SLIDE 39

Variance of the primary estimator

 

( )

2 2 2 prim 2 prim 2 prim prim

d ) ( ] [ ] [ I x x p x f F E F E F V − = − = =

For an unbiased estimator, the error is due to variance: If we use only a single sample, the variance is usually too high. We need more samples in practice => secondary estimator.

(for an unbiased estimator)

CG III (NPGR010) - J. Křivánek 2015 39

slide-40
SLIDE 40

Secondary estimator of an integral

◼ Consider N independent random variables Xi ◼ The estimator FN given be the formula below is called the

secondary estimator of I.

◼ The secondary estimator is unbiased.

CG III (NPGR010) - J. Křivánek 2015 40

( ) ( )

=

=

N i i i N

X p X f N F

1

1

slide-41
SLIDE 41

Variance of the secondary estimator  

 

prim 2 1 i

1 ) ( ) ( 1 ) ( ) ( 1 F V N X p X f V N N X p X f N V F V

i i N i i N

=         =       =

=

... standard deviation is N-times smaller! (i.e. error converges with 1/N)

CG III (NPGR010) - J. Křivánek 2015 41

slide-42
SLIDE 42

Properties of estimators

slide-43
SLIDE 43

Unbiased estimator

◼ A general statistical estimator is called unbiased if –

“on average” – it yields the correct value of an estimated quantity Q (without systematic error).

◼ More precisely:

CG III (NPGR010) - J. Křivánek 2015 43

 

Q F E =

Estimated quantity (In our case, it is an integral, but in general it could be

  • anything. It is a number, not a

random variable.) Estimator of the quantity Q (random variable)

slide-44
SLIDE 44

Bias of a biased estimator

◼ If

then the estimator is “biased” (cz: vychýlený).

◼ Bias is the systematic error of he estimator:

CG III (NPGR010) - J. Křivánek 2015 44

 

Q F E 

 

F E Q − = 

slide-45
SLIDE 45

Consistency

◼ Consider a secondary estimator with N samples: ◼ Estimator FN is consistent if

i.e. if the error FN – Q converges to zero with probability 1.

CG III (NPGR010) - J. Křivánek 2015 45

) ,..., , (

2 1 N N N

X X X F F =

slide-46
SLIDE 46

Consistency

◼ Sufficient condition for consistency of an estimator: ◼ Unbiasedness is not sufficient for consistency by itself (if

the variance is infinite).

◼ But if the variance of a primary estimator finite, then the

corresponding secondary estimator is necessarily consistent.

CG III (NPGR010) - J. Křivánek 2015 46

bias

slide-47
SLIDE 47

Rendering algorithms

◼ 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 47

slide-48
SLIDE 48

Mean Squared Error – MSE (cz: Střední kvadratická chyba)

◼ Definition ◼ Proposition

❑ Proof

CG III (NPGR010) - J. Křivánek 2015 48

] ) [( ] [

2

Q F E F MSE − =

2

] [ ] [ ] [ F F V F MSE  + =

slide-49
SLIDE 49

Mean Squared Error – MSE (cz: Střední kvadratická chyba)

◼ If the estimator F is unbiased, then

i.e. for an unbiased estimator, it is much easier to estimate the error, because it can be estimated directly from the samples Yi = f(Xi) / p(Xi).

◼ Unbiased estimator of variance

CG III (NPGR010) - J. Křivánek 2015 49

] [ ] [ F V F MSE =

slide-50
SLIDE 50

Root Mean Squared Error – RMSE

CG III (NPGR010) - J. Křivánek 2015 50

] [ ] [ F MSE F RMSE =

slide-51
SLIDE 51

Efficiency of an estimator

◼ Efficiency of an unbiased estimator is given by:

CG III (NPGR010) - J. Křivánek 2015 51

variance Calculation time (i.e. operations count, such as number of cast rays)

slide-52
SLIDE 52

MC estimators for illumination calculation

slide-53
SLIDE 53

◼ PDF for uniform sampling: ◼ Estimator:

Irradiance estimator – uniform sampling

CG III (NPGR010) - J. Křivánek 2015 53

 =

) ( i i i i

d cos ) , ( ) (

x

x x

H

L E      2 1 ) ( = p

( ) ( )

 

= =

 = =

N k ,k k N k k k N

L N p f N F

1 i i, i 1 i, i,

cos ) , ( 2 1      x

◼ Integral to be estimated:

slide-54
SLIDE 54

Irradiance estimator – cosine- proportional sampling

CG III (NPGR010) - J. Křivánek 2015 54

( ) ( )

 

= =

= =

N k ,k N k ,k ,k N

L N p f N F

1 i i 1 i i

) , ( 1     x

◼ PDF for cosine-

proportional sampling:

◼ Estimator ◼ Integral to be estimated:

 =

) ( i i i i

d cos ) , ( ) (

x

x x

H

L E       cos ) ( = p

slide-55
SLIDE 55

Irradiance estimate – light source sampling

CG III (NPGR010) - J. Křivánek 2015 55

slide-56
SLIDE 56

Irradiance estimate – light source sampling

◼ Reformulate the reflection integral (change of variables) ◼ PDF for uniform sampling of the surface area: ◼ Estimator

CG III (NPGR010) - J. Křivánek 2015 56

 

−     → =  =

A H

A V L L E d cos cos ) ( ) ( d cos ) , ( ) (

2 e ) ( i i i i

x y x y x y x x

x y x

     ) ( x y  G A p 1 ) ( = y

=

    → =

N k k k k N

G V L N A F

1 e

) ( ) ( ) ( x y x y x y

slide-57
SLIDE 57

Light source vs. cosine sampling

CG III (NPGR010) - J. Křivánek 2015 57

Light source area sampling Cosine-proportional sampling Images: Pat Hanrahan

slide-58
SLIDE 58

CG III (NPGR010) - J. Křivánek 2015 58

slide-59
SLIDE 59

CG III (NPGR010) - J. Křivánek 2015 59

slide-60
SLIDE 60

Area light sources

1 sample per pixel 9 samples per pixel 36 samples per pixel

CG III (NPGR010) - J. Křivánek 2015 60

slide-61
SLIDE 61

Direct illumination on a surface with an arbitrary BRDF

◼ Integral to be estimated ◼ Estimator based on uniform light source sampling

CG III (NPGR010) - J. Křivánek 2015 61

    → →  → =

A r

A G V f L L d ) ( ) ( ) ( ) ( ) , (

  • e
  • x

y x y x y x y x  

=

    → →  → =

N k k k k r k N

G V f L N A F

1

  • e

) ( ) ( ) ( ) ( x y x y x y x y 