Course Notes

advertisement
Monte Carlo Path Tracing
Coursework Notes
Insu Yu (Research Fellow)
i.yu@cs.ucl.ac.uk
James Tompkin (Research Engineer & T.A.)
j.tompkin@cs.ucl.ac.uk (email me with questions)
Insu Yu 2006, James Tompkin 2010
What you need to do (in brief)
1.
2.
3.
4.
5.
6.
7.
Shoot many rays through each pixel with stratified, jittered
sampling.
Modify the direct lighting calculations to add support for area
light sources.
Add support for sampling a BRDF.
Add support for evaluating the BRDFs at a surface point.
Put it all together to form paths that sample all the integrals;
pixels, direct lighting and BRDFs.
Add importance sampling OR unbiased path termination
(Russian roulette).
Make your own scenes.
Path Tracing
Review
Simple Stochastic Path Tracing
 Radiance for each ray (eye to pixel in view plane) is calculated by
L( x  Eye)
L( x  )  Le ( x  )  Lr ( x  )
Lr ( x  ) 
 L( x ) f ( x,   ) cos( N , )d
r
x

x
 The integral cam be evaluated using Monte Carlo integration by generating N random direction ψi
on hemisphere Ωx distributed according to some probability density function P(x)
1 N L( x   i ) f r ( x,   ) cos( N x , )
L( x  )  Le ( x  ) 

N i 1
p( i )
Monte Carlo Path Tracing
 Rendering Equation
L( x  )  Le ( x  )  Lr ( x  )
Lr ( x  ) 
 L( x ) f ( x,   ) cos( N , )d
r
x

x
Lr ( x  )  Direct ( Area formulation)
 Indirect ( Hemisphere formulation)
Monte Carlo Path Tracing
Lr ( x  )  Direct ( Area formulation)  Indirect (Hemisphere formulation)
Direct ( Area formulation)
  Le ( y  yx) f r ( x, xy  ) V ( x, y )  G ( x, y )dAy
A
1 N  Le ( yi  yi x) f r ( x, xyi  ) V ( x, yi )  G ( x, yi ) 
 

N i 1 
p( yi )

Indirect ( Hemisphere formulation)
  Li ( x   ) f r ( x,   ) cos( N x ,  )d

1 N  Li ( x   ) f r ( x,   ) cos( N x ,  ) 
 

N i 1 
p( i )

The Coursework
Notes for each part
Part 1: Stratified Jittered sampling
Function: LitScene::renderPixel, SimpleCamera::StratifiedRandomRay
 Generate N x N stratified Sample per pixel at (i,j)
 Generate random variable λ1 & λ2 to index stratified sample
 Generate Ray: COP to sampled position at (i+ λ1,j+ λ2)
 Radiance = Total Radiance / N_RAYS_PER_PIXEL
 Remember to change N_RAYS_PER_PIXEL = 1 to 1, 64,
256, 1024 rays, etc.
Part 2: Direct Lighting
Area light source sampling
Direct ( Area formulation)
  Le ( y  yx) f r ( x, xy  ) V ( x, y )  G ( x, y )dAy
A
1 N  Le ( yi  yi x) f r ( x, xyi  ) V ( x, yi )  G ( x, yi ) 
 

N i 1 
p( yi )

G ( x, y ) 
cos 1 cos  2 cos( N x , yi x)  cos( N y1 , xyi )

2
rxy
rxy 2
Part 2: Direct Lighting
Example: Spherical Light sampling
 Samples the sphere over the solid angle as seen from a point
 Find direction toward sphere in polar coordinates :


 r

 ' arccos 1  1   2 1  

 '  
 xc

 

2 2




2


 



 Transform local to world coordinates
with U,V,N.
 Find intersection point (x’):
PDF ( x ') 

( ' n ')
2 



r
2 x  x ' 1  1  
 

 x  c  

Reference: Section 3.2 'Sampling Spherical Luminaries’ in "Monte Carlo Techniques for Direct
Lighting Calculations," ACM Transactions on Graphics, 1996
Part 2: Direct Lighting
Polygon Light sampling
Function: Polygon::TriangularSampling, Polygon::RectangularSampling
 Sampling Rectangular Luminaries
 The uniform random sampled are given by:
x '  x0  1 v1  2 v2
PDF ( x ')  1/ v1  v2
 Sampling Triangular Luminaries
 Use barycentric coordinates of triangles.
 The uniform random sampled are given by:
x'  p0   2 1  1 ( p1  p0 )  (1  1  1 )( p2  p0 )
PDF ( x ')  2 / v1  v2
 Sampling Polygon Luminaries
 Up to you!

Reference: Section 3.3 'Sampling Planar Luminaires’ in "Monte Carlo Techniques for Direct Lighting
Calculations," ACM Transactions on Graphics, 1996
Part 3,4,5:
Lambertian Reflection Model
Function: lambertianBRDF::reflection, lambertianBRDF::brdf
L( x  )  Le ( x  )  Lr ( x  )
1
L( x  )  Le ( x  ) 
N
PDF  p ( ) 
cos 


cos( N x ,  )

N

i 1
L( x   i ) f r ( x,   ) cos( N x ,  i )
p( i )
BRDF  f r ( x,   )  K d 
d

x  cos(21 ) 1  2
y 
z
2
 sin(21 ) 1  2
Part 3,4,5:
Modified Phong Reflection Model
Function: phongBRDF::reflection, phongBRDF::brdf
L( x  )  Le ( x  )  Lr ( x  )
Lr ( x  ) 
 L( x ) f ( x,   ) cos( N , )d
r
x

x
 Diffuse  Specular

 L( x ) K
x
d
cos( N x ,  )d 
 L( x ) K
s
cos n ( R, )  cos( N x , )d
x
1 N L( x   i )  K d  cos( N x ,  i )
1 N L( x   i ) K s cos n ( R,  )  cos( N x ,  )




N i 1
p1 ( i )
N i 1
p2 ( i )
Part 3,4,5:
Modified Phong Reflection Model
 Diffuse  Specular

 L( x ) K
x
d
cos( N x ,  )d 
 L( x ) K
s
cos n ( R, )  cos( N x , )d
x
1 N L( x   i )  K d  cos( N x ,  i )
1 N L( x   i ) K s cos n ( R,  )  cos( N x ,  )




N i 1
p1 ( i )
N i 1
p2 ( i )
Part 3,4,5:
Modified Phong Reflection Model
Function: phongBRDF:reflection, phongBRDF:brdf
Part 3,4,5:
Modified Phong Reflection Model
Part 3,4,5:
Modified Phong Reflection Model
 Reading Lafortune and Willem’s Using the Modified Phong
Reflectance Model for Physically-based Rendering will help.
Part 6:
Importance Sampling/Russian Roulette
 Look up the references on the webpage for these techniques
to read more about them.
 Reading Avro and Kirk’s Particle Transport and Image Synthesis is
a good place to start.
Part 7:
D.I.Y. scenes
 Try to demonstrate advantages and disadvantages of path
tracing in your scenes.
 What limitations exist? Which types of scene require more
sampling to reduce noise?
General Tips
 Use the paper references!
 They contain valuable background information which will help
you understand the problem.
 Dutre’s Global Illumination Compendium is named precisely.
 A simple screenshot function exists in mainray.cpp for
automating capture to .bmp.You can use it for your
documentation.
 screenshot(int windowWidth, int windowHeight, char* filename)
 Any other questions, e-mail j.tompkin@cs.ucl.ac.uk
Download