monte carlo path tracing - computer graphics · 2005. 5. 12. · page 2 cs348b lecture 14 pat...

16
Page 1 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Monte Carlo Path Tracing Today Path tracing Random walks and Markov chains Eye vs. light ray tracing Bidirectional ray tracing Next Irradiance caching Photon mapping CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Path 0 1 2 3 0 1 1 0 1 2 1 2 1 2 3 ( , , , ) ( , )( , ) ( , , )( , ) ( , , ) S o r r Lx xx x Sx xGxx fx xxGxx fxx x = 0 x 1 x 2 x 1 2 ( , ) Gx x 0 1 2 ( , , ) r f x x x 1 2 3 ( , , ) r f x x x 0 1 ( , ) Sx x 0 1 ( , ) Gx x 0 1 2 3 ( , , , ) S L x x x x

Upload: others

Post on 12-Nov-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 1

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Monte Carlo Path Tracing

Today

Path tracing

Random walks and Markov chains

Eye vs. light ray tracing

Bidirectional ray tracing

Next

Irradiance caching

Photon mapping

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Light Path

0 1 2 3 0 1 1 0 1 2 1 2 1 2 3( , , , ) ( , ) ( , ) ( , , ) ( , ) ( , , )S o r rL x x x x S x x G x x f x x x G x x f x x x=

0x

1x

2x1 2( , )G x x

0 1 2( , , )rf x x x

1 2 3( , , )rf x x x0 1( , )S x x

0 1( , )G x x

0 1 2 3( , , , )SL x x x x

Page 2: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 2

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Light Transport

Integrate over all paths

Questions

How to sample space of paths

2 2

1

0 2 1 0 21

( , )

( , , , , ) ( ) ( )

k k

S k k k kk M M

L x x

L x x x x dA x dA x

− − −=

= ∑ ∫ ∫

Path Tracing

Page 3: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 3

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Penumbra: Trees vs. Paths

4 eye rays per pixel16 shadow rays per eye ray

64 eye rays per pixel1 shadow ray per eye ray

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Path Tracing: From Camera

Step 1. Choose a camera ray r given the (x,y,u,v,t) sample

weight = 1;

Step 2. Find ray-surface intersection

Step 3.

if light

return weight * Le();

else

weight *= reflectance(r)

Choose new ray r’ ~ BRDF pdf(r)

Go to Step 2.

Page 4: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 4

CS348B Lecture 14 Pat Hanrahan, Spring 2005

M. Fajardo Arnold Path Tracer

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Cornell Box: Path Tracing

10 rays per pixel 100 rays per pixel

From Jensen, Realistic Image Synthesis Using Photon Maps

Page 5: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 5

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Path Tracing: Include Direct Lighting

Step 1. Choose a camera ray r given the (x,y,u,v,t) sample

weight = 1;

Step 2. Find ray-surface intersection

Step 3.

weight += Lr(light sources)

Choose new ray r’ ~ BRDF pdf(r)

Go to Step 2.

Discrete Random Walk

Page 6: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 6

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Discrete Random Process

Creation Termination

Transition

States

0 : probability of creation in state ip i

, : probability of transition from state i jp i j→* : probability of termination in state ip i

*,1i i j

j

p p= −∑

Assign probabilities to each process

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Discrete Random Process

Creation Termination

Transition

States

0,i i j j i

jP p P p= +∑

Equilibrium number of particles in each state

0P MP p= +

, ,i j i jM p=

Page 7: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 7

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Discrete Random Walk

1. Generate random particles from sources.

2. Undertake a discrete random walk.

3. Count how many terminate in state i

[von Neumann and Ulam; Forsythe and Leibler; 1950s]

Creation Termination

Transition

States

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Monte Carlo Algorithm

Define a random variable on the space of paths

Path:

Probability:

Estimator:

Expectation:

1

[ ] ( ) ( )k

k kk

E W P Wα

α α∞

=

= ∑∑

1 2( , , , )k ki i iα = …

( )kP α

( )kW α

Page 8: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 8

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Monte Carlo Algorithm

Define a random variable on the space of paths

Probability:

Estimator:

1 1 2 1

0 *, ,( )

k k kk i i i i i iP p p p pα−

= × ×

,

*( ) k

k

i jj k

i

Wp

δα =

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Estimator

Count the number of particles terminating in state j

1 1 2 1

1

,0 *, , *

1

0 0 2 0

[ ] ( ) k

k k k

k

i jj i i i i i i

k i i j

j j j

E W p p p pp

p Mp M p

δ−

=

=

= + +

∑∑ ∑

Page 9: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 9

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Equilibrium Distribution of States

Total probability of being in states P

Note that this is the solution of the equation

Thus, the discrete random walk is an unbiased estimate of the equilibrium number of particles in each state

( )2 0P I M M p= + + +

0( )I M P p− =

Light Ray Tracing

Page 10: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 10

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Examples

Backward ray tracing, Arvo 1986

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Path Tracing: From Lights

Step 1. Choose a light ray

Choose a light source according to the light source power distribution function.

Choose a ray from the light source radiance (area) or intensity (point) distribution function

w = 1;

Step 2. Trace ray to find surface intersect

Step 3. Interaction

Page 11: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 11

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Path Tracing: From Lights

Step 1. Choose a light ray

Step 2. Find ray-surface intersection

Step 3. Interaction

u = rand()

if u < reflectance

Choose new ray r ~ BRDF

goto Step 2

else

terminate on surface; deposit energy

Bidirectional Path Tracing

Page 12: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 12

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Bidirectional Ray Tracing

0, 3l e= = 1, 2l e= =

3, 0l e= =2, 1l e= =

k l e= +

3k =

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Path Pyramid

3=k

4=k

5=k

6=k

l e

)1,5( == el

)1,2( == el

From Veach and Guibas

Page 13: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 13

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Comparison

Bidirectional path tracing Path tracing

From Veach and Guibas

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Generating All Paths

Page 14: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 14

Adjoint Formulation

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Symmetric Light Path

0 1 1 0 1 2 1 2 1 2 3 2 3 2 3( , ) ( , ) ( , , ) ( , ) ( , , ) ( , ) ( , )o r rM S x x G x x f x x x G x x f x x x G x x R x x=

0x

1x

2x1 2( , )G x x

0 1 2( , , )rf x x x

1 2 3( , , )rf x x x0 1( , )S x x

0 1( , )G x x

2 3( , )R x x

3x

2 3( , )G x x

Page 15: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 15

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Symmetric Light Path

= 0 1 0 1 0 1 2 1 2 1 2 3 2 3 2 3( , ) ( , ) ( , , ) ( , ) ( , , ) ( , ) ( , )r rM S x x G x x f x x x G x x f x x x G x x R x x

0x

1x

2x1 2( , )G x x

0 1 2( , , )rf x x x

=1 2 3 3 2 1( , , ) ( , , )r rf x x x f x x x0 1( , )S x x

0 1( , )G x x

2 3( , )R x x

3x

=2 3 3 2( , ) ( , )G x x G x x

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Symmetric Light Path

= 3 2 3 2 3 2 1 2 1 2 1 0 1 0 1 0( , ) ( , ) ( , , ) ( , ) ( , , ) ( , ) ( , )r rM R x x G x x f x x x G x x f x x x G x x S x x

0x

1x

2x2 1( , )G x x

2 1 0( , , )rf x x x

3 2 1( , , )rf x x x1 0( , )S x x

1 0( , )G x x

3 2( , )R x x

3x

3 2( , )G x x

Page 16: Monte Carlo Path Tracing - Computer Graphics · 2005. 5. 12. · Page 2 CS348B Lecture 14 Pat Hanrahan, Spring 2005 Light Transport Integrate over all paths Questions How to sample

Page 16

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Three Consequences

1. Forward estimate equal backward estimate

- May use forward or backward ray tracing

2. Adjoint solution

- Importance sampling paths

3. Solve for small subset of the answer

CS348B Lecture 14 Pat Hanrahan, Spring 2005

Example: Linear Equations

Solve a linear system

Solve for a single xi?

Solve the adjoint equation

Source

Estimator

More efficient than solving for all the unknowns

[von Neumann and Ulam]

Mx b=

ix2( ),i i ix Mx M x b< + + + >