monte carlo integration cos 323 acknowledgment: tom funkhouser

53
Monte Carlo Integration Monte Carlo Integration COS 323 COS 323 cknowledgment: Tom Funkhouser cknowledgment: Tom Funkhouser

Post on 21-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Integration Monte Carlo Integration

COS 323COS 323

Acknowledgment: Tom FunkhouserAcknowledgment: Tom Funkhouser

Page 2: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Integration in 1DIntegration in 1D

x=1x=1

f(x)f(x)

?)(1

0 dxxf ?)(1

0 dxxf

Slide courtesy of Slide courtesy of Peter ShirleyPeter Shirley

Page 3: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

We can approximateWe can approximate

x=1x=1

f(x)f(x) g(x)g(x)

1

0

1

0

)()( dxxgdxxf 1

0

1

0

)()( dxxgdxxf

Slide courtesy of Slide courtesy of Peter ShirleyPeter Shirley

Page 4: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Or we can averageOr we can average

x=1x=1

f(x)f(x) E(f(x))E(f(x))

))(()(1

0

xfEdxxf ))(()(1

0

xfEdxxf

Slide courtesy of Slide courtesy of Peter ShirleyPeter Shirley

Page 5: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Estimating the averageEstimating the average

xx11

f(x)f(x)

xxNN

N

iixfN

dxxf1

1

0

)(1

)(

N

iixfN

dxxf1

1

0

)(1

)(

E(f(x))E(f(x))

Slide courtesy of Slide courtesy of Peter ShirleyPeter Shirley

Page 6: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Other DomainsOther Domains

x=bx=b

f(x)f(x) < f >< f >abab

x=ax=a

N

ii

b

a

xfN

abdxxf

1

)()(

N

ii

b

a

xfN

abdxxf

1

)()(

Slide courtesy of Slide courtesy of Peter ShirleyPeter Shirley

Page 7: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Benefits of Monte CarloBenefits of Monte Carlo

• No “exponential explosion” in required No “exponential explosion” in required number of samples with increase in number of samples with increase in dimensiondimension

• Resistance to badly-behaved functionsResistance to badly-behaved functions

Page 8: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

VarianceVariance

xx11 xxNN

E(f(x))E(f(x))

2

1

))](()([1

)( xfExfN

xfVarN

ii

2

1

))](()([1

)( xfExfN

xfVarN

ii

Page 9: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

VarianceVariance

xx11 xxNN

E(f(x))E(f(x))

)(1))(( xfVar

NxfEVar )(1))(( xfVar

NxfEVar

Variance decreases as 1/NVariance decreases as 1/NError decreases as 1/sqrt(N)Error decreases as 1/sqrt(N)

Page 10: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

VarianceVariance

• Problem: variance decreases with 1/NProblem: variance decreases with 1/N– Increasing # samples removes noise slowlyIncreasing # samples removes noise slowly

xx11 xxNN

E(f(x))E(f(x))

Page 11: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Variance Reduction TechniquesVariance Reduction Techniques

• Problem: variance decreases with 1/NProblem: variance decreases with 1/N– Increasing # samples removes noise slowlyIncreasing # samples removes noise slowly

• Variance reduction:Variance reduction:– Stratified samplingStratified sampling

– Importance samplingImportance sampling

Page 12: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Stratified SamplingStratified Sampling

• Estimate subdomains separatelyEstimate subdomains separately

xx11 xxNN

EEkk(f(x))(f(x))

ArvoArvo

Page 13: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Stratified SamplingStratified Sampling

• This is still unbiasedThis is still unbiased

M

kii

N

iiN

FNN

xfN

F

1

1

1

)(1

M

kii

N

iiN

FNN

xfN

F

1

1

1

)(1

xx11 xxNN

EEkk(f(x))(f(x))

Page 14: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Stratified SamplingStratified Sampling

• Less overall variance if less variance Less overall variance if less variance in subdomainsin subdomains

M

kiiN FVarN

NFVar

12

1

M

kiiN FVarN

NFVar

12

1

xx11 xxNN

EEkk(f(x))(f(x))

Page 15: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• Put more samples where f(x) is biggerPut more samples where f(x) is bigger

)(

)(

1)(

1

i

ii

N

ii

xp

xfY

YN

dxxf

)(

)(

1)(

1

i

ii

N

ii

xp

xfY

YN

dxxf

xx11 xxNN

E(f(x))E(f(x))

Page 16: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• This is still unbiasedThis is still unbiased

xx11 xxNN

E(f(x))E(f(x))

dxxf

dxxpxp

xf

dxxpxYYE i

)(

)()(

)(

)()(

dxxf

dxxpxp

xf

dxxpxYYE i

)(

)()(

)(

)()(

for all Nfor all N

Page 17: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• Zero variance if p(x) ~ f(x)Zero variance if p(x) ~ f(x)

x1 xN

E(f(x))

Less variance with betterLess variance with betterimportance samplingimportance sampling

0)(

1

)(

)(

)()(

YVar

cxp

xfY

xcfxp

i

ii

0)(

1

)(

)(

)()(

YVar

cxp

xfY

xcfxp

i

ii

Page 18: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Generating Random PointsGenerating Random Points

• Uniform distribution:Uniform distribution:– Use pseudorandom number generatorUse pseudorandom number generator

Pro

bab

ility

Pro

bab

ility

00

11

Page 19: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Pseudorandom NumbersPseudorandom Numbers

• Deterministic, but have statistical properties Deterministic, but have statistical properties resembling true random numbersresembling true random numbers

• Common approach: each successive Common approach: each successive pseudorandom number is function of pseudorandom number is function of previousprevious

• Linear congruential method:Linear congruential method:– Choose constants carefully, e.g.Choose constants carefully, e.g.

a = 1664525a = 1664525b = 1013904223b = 1013904223c = 2c = 232 32 – 1– 1

cbaxx nn mod1 cbaxx nn mod1

Page 20: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Pseudorandom NumbersPseudorandom Numbers

• To get floating-point numbers in [0..1),To get floating-point numbers in [0..1),divide integer numbers by divide integer numbers by cc + 1 + 1

• To get integers in range [u..v], divide byTo get integers in range [u..v], divide by(c+1)/(v–u+1), truncate, and add u(c+1)/(v–u+1), truncate, and add u– Better statistics than using modulo (v–u+1)Better statistics than using modulo (v–u+1)

– Only works if u and v small compared to cOnly works if u and v small compared to c

Page 21: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Generating Random PointsGenerating Random Points

• Uniform distribution:Uniform distribution:– Use pseudorandom number generatorUse pseudorandom number generator

Pro

bab

ility

Pro

bab

ility

00

11

Page 22: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• Specific probability distribution:Specific probability distribution:– Function inversionFunction inversion

– RejectionRejection

)(xf )(xf

Page 23: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• ““Inversion method”Inversion method”– Integrate Integrate ff((xx): Cumulative Distribution ): Cumulative Distribution

FunctionFunction

dxxf )( dxxf )(1111

)(xf )(xf

Page 24: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• ““Inversion method”Inversion method”– Integrate Integrate ff((xx): Cumulative Distribution ): Cumulative Distribution

FunctionFunction

– Invert CDF, apply to uniform random Invert CDF, apply to uniform random variablevariable dxxf )( dxxf )(

1111

)(xf )(xf

Page 25: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• Specific probability distribution:Specific probability distribution:– Function inversionFunction inversion

– RejectionRejection

)(xf )(xf

Page 26: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Generating Random PointsGenerating Random Points

• ““Rejection method”Rejection method”– Generate random (x,y) pairs,Generate random (x,y) pairs,

y between 0 and max(fy between 0 and max(f((xx))) )

Page 27: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Generating Random PointsGenerating Random Points

• ““Rejection method”Rejection method”– Generate random (x,y) pairs,Generate random (x,y) pairs,

y between 0 and max(fy between 0 and max(f((xx))))

– Keep only samples where y < f(x)Keep only samples where y < f(x)

Page 28: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo in Computer Monte Carlo in Computer GraphicsGraphics

Page 29: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

or, Solving Integral Equationsor, Solving Integral Equationsfor Fun and Profitfor Fun and Profit

Page 30: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

or, Ugly Equations, Pretty or, Ugly Equations, Pretty PicturesPictures

Page 31: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

AnimationAnimationAnimationAnimation

Computer Graphics PipelineComputer Graphics Pipeline

RenderingRenderingRenderingRendering

LightingLightingandand

ReflectanceReflectance

LightingLightingandand

ReflectanceReflectance

ModelingModelingModelingModeling

Page 32: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

xx

''

Rendering EquationRendering Equation

SurfaceSurfaceLightLight

dnxfxLxLxL rieo )()',,(),()',()',(

dnxfxLxLxL rieo )()',,(),()',()',(

dd

[Kajiya 1986][Kajiya 1986]

ViewerViewer

nn

Page 33: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Rendering EquationRendering Equation

• This is an This is an integral equationintegral equation

• Hard to solve!Hard to solve!– Can’t solve thisCan’t solve this

in closed formin closed form

– Simulate complexSimulate complexphenomenaphenomena

HeinrichHeinrich

dnxfxLxLxL rieo )()',,(),()',()',(

dnxfxLxLxL rieo )()',,(),()',()',(

Page 34: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Rendering EquationRendering Equation

• This is an This is an integral equationintegral equation

• Hard to solve!Hard to solve!– Can’t solve thisCan’t solve this

in closed formin closed form

– Simulate complexSimulate complexphenomenaphenomena

JensenJensen

dnxfxLxLxL rieo )()',,(),()',()',(

dnxfxLxLxL rieo )()',,(),()',()',(

Page 35: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo IntegrationMonte Carlo Integration

f(x)f(x)

N

iixfN

dxxf1

1

0

)(1

)(

N

iixfN

dxxf1

1

0

)(1

)(

ShirleyShirley

Page 36: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Path TracingMonte Carlo Path Tracing

Estimate integral Estimate integral for each pixel for each pixel

by random samplingby random sampling

Estimate integral Estimate integral for each pixel for each pixel

by random samplingby random sampling

Page 37: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

Page 38: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

SurfaceSurface

EyeEye

PixelPixel

xx

dAe)L(xLS

P dAe)L(xLS

P

Page 39: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

SurfaceSurface

EyeEye

LightLight

xx

x’x’

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

Page 40: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

HerfHerf

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

Page 41: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

SurfaceSurface

EyeEye

LightLight

xx

SurfaceSurface

’’

Page 42: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

DebevecDebevec

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

Page 43: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

Diffuse SurfaceDiffuse Surface

EyeEye

LightLight

xx

SpecularSpecularSurfaceSurface

’’

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

Page 44: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Global IlluminationMonte Carlo Global Illumination

• Rendering = integrationRendering = integration– AntialiasingAntialiasing

– Soft shadowsSoft shadows

– Indirect illuminationIndirect illumination

– CausticsCaustics

JensenJensen

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

wdnw)w(x,Lwwxf)w(x,L)w(x,L ireo

)(),,(

Page 45: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

ChallengeChallenge

• Rendering integrals are difficult to Rendering integrals are difficult to evaluateevaluate– Multiple dimensionsMultiple dimensions

– DiscontinuitiesDiscontinuities• Partial occludersPartial occluders

• HighlightsHighlights

• CausticsCaustics

DrettakisDrettakis

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

Page 46: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

ChallengeChallenge

• Rendering integrals are difficult to Rendering integrals are difficult to evaluateevaluate– Multiple dimensionsMultiple dimensions

– DiscontinuitiesDiscontinuities• Partial occludersPartial occluders

• HighlightsHighlights

• CausticsCaustics

JensenJensen

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

dAxxGxxx)VxL(exxxxfe)(x,xL)wL(x,S

re ),(),(),,(

Page 47: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Path TracingMonte Carlo Path Tracing

Big diffuse light source, 20 minutesBig diffuse light source, 20 minutes

JensenJensen

Page 48: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Path TracingMonte Carlo Path Tracing

1000 paths/pixel1000 paths/pixel

JensenJensen

Page 49: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Path TracingMonte Carlo Path Tracing

• Drawback: can beDrawback: can benoisy unless noisy unless lotslots of ofpaths simulatedpaths simulated

• 40 paths per pixel:40 paths per pixel:

LawrenceLawrence

Page 50: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Monte Carlo Path TracingMonte Carlo Path Tracing

• Drawback: can beDrawback: can benoisy unless noisy unless lotslots of ofpaths simulatedpaths simulated

• 1200 paths per pixel:1200 paths per pixel:

LawrenceLawrence

Page 51: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Reducing VarianceReducing Variance

• Observation: some paths more importantObservation: some paths more important(carry more energy) than others(carry more energy) than others– For example, shiny surfaces reflect more lightFor example, shiny surfaces reflect more light

in the ideal “mirror” directionin the ideal “mirror” direction

• Idea: put more samples where f(x) is Idea: put more samples where f(x) is biggerbigger

Page 52: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Importance SamplingImportance Sampling

• Idea: put more samples where f(x) is Idea: put more samples where f(x) is biggerbigger

)(

)(

1)(

1

1

0

i

ii

N

ii

xp

xfY

YN

dxxf

)(

)(

1)(

1

1

0

i

ii

N

ii

xp

xfY

YN

dxxf

Page 53: Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser

Effect of Importance SamplingEffect of Importance Sampling

• Less noise at a given number of samplesLess noise at a given number of samples

• Equivalently, need to simulate fewer Equivalently, need to simulate fewer paths for some desired limit of noisepaths for some desired limit of noise

Uniform random samplingUniform random sampling Importance samplingImportance sampling