Insu Yu (Research Fellow)[email protected]
James Tompkin (Research Engineer & T.A.)[email protected] (email me with questions)
Monte Carlo Path Tracing Coursework Notes
Insu Yu 2006, James Tompkin 2010
What you need to do (in brief)1. Shoot many rays through each pixel with
stratified, jittered sampling.2. Modify the direct lighting calculations to add
support for area light sources.3. Add support for sampling a BRDF. 4. Add support for evaluating the BRDFs at a
surface point. 5. Put it all together to form paths that sample all
the integrals; pixels, direct lighting and BRDFs.6. Add importance sampling OR unbiased path
termination (Russian roulette).7. Make your own scenes.
Path Tracing
Review
Simple Stochastic Path Tracing
Radiance for each ray (eye to pixel in view plane) is calculated by
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)
( ) ( ) ( )e rL x L x L x
( ) ( ) ( , ) cos( , )x
r r xL x L x f x N d
( )L x Eye
1
( ) ( , ) cos( , )1( ) ( )
( )
Ni r x
ei i
L x f x NL x L x
N p
Monte Carlo Path Tracing
Rendering Equation
( ) ( ) ( )e rL x L x L x
( ) ( ) ( , ) cos( , )x
r r xL x L x f x N d
( ) ( )
( )rL x Direct Area formulation
Indirect Hemisphere formulation
Monte Carlo Path Tracing
1
( )
( ) ( , ) cos( , )
( ) ( , ) cos( , )1
( )
i r x
Ni r x
i i
Indirect Hemisphere formulation
L x f x N d
L x f x N
N p
1
( )
( ) ( , ) ( , ) ( , )
( ) ( , ) ( , ) ( , )1
( )
e r y
A
Ne i i r i i i
i i
Direct Area formulation
L y yx f x xy V x y G x y dA
L y y x f x xy V x y G x y
N p y
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
( ) ( ) ( )rL x Direct Area formulation Indirect Hemisphere formulation
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
1
( )
( ) ( , ) ( , ) ( , )
( ) ( , ) ( , ) ( , )1
( )
e r y
A
Ne i i r i i i
i i
Direct Area formulation
L y yx f x xy V x y G x y dA
L y y x f x xy V x y G x y
N p y
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 22 2
cos( , ) cos( , )cos cos( , ) x i y i
xy xy
N y x N xyG x y
r r
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Part 2: Direct Lighting Example: Spherical Light sampling
Samples the sphere over the solid angle as seen from a pointFind direction toward sphere in polar coordinates :
Transform local to world coordinates with U,V,N.
Find intersection point (x’):
Reference: Section 3.2 'Sampling Spherical Luminaries’ in "Monte Carlo Techniques for Direct Lighting Calculations," ACM Transactions on Graphics, 1996
2
( ' ')( ')
2 ' 1 1
nPDF x
rx x
x c
;;;;;;;;;;;;;;
2
1 2
2
arccos 1 1'
'
2
r
x c
Part 2: Direct Lighting Polygon Light sampling Function: Polygon::TriangularSampling, Polygon::RectangularSampling
Sampling Rectangular LuminariesThe uniform random sampled are given by:
Sampling Triangular LuminariesUse barycentric coordinates of triangles.The uniform random sampled are given by:
Sampling Polygon LuminariesUp to you!
Reference: Section 3.3 'Sampling Planar Luminaires’ in "Monte Carlo Techniques for Direct Lighting Calculations," ACM Transactions on Graphics, 1996
0 1 1 2 2'x x v v ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 2( ') 1/PDF x v v ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 2( ') 2 /PDF x v v ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
))(11()(1' 02101120 pppppx
cos( , )cos( ) xNPDF p
1
( ) ( ) ( )
( ) ( , ) cos( , )1( ) ( )
( )
e r
Ni r x i
ei i
L x L x L x
L x f x NL x L x
N p
( , ) dr dBRDF f x K
1 2
2
1 2
cos(2 ) 1
sin(2 ) 1
x
y
z
Part 3,4,5: Lambertian Reflection Model
Function: lambertianBRDF::reflection, lambertianBRDF::brdf
( ) ( ) ( )
( ) ( ) ( , ) cos( , )x
e r
r r x
L x L x L x
L x L x f x N d
1 11 2
( ) cos( , ) ( ) cos ( , ) cos( , )
( ) cos( , ) ( ) cos ( , ) cos( , )1 1
( ) ( )
x x
nd x s x
nN Ni d x i i s x
i ii i
Diffuse Specular
L x K N d L x K R N d
L x K N L x K R N
N p N p
Part 3,4,5: Modified Phong Reflection Model
Function: phongBRDF::reflection, phongBRDF::brdf
Part 3,4,5: Modified Phong Reflection Model
1 11 2
( ) cos( , ) ( ) cos ( , ) cos( , )
( ) cos( , ) ( ) cos ( , ) cos( , )1 1
( ) ( )
x x
nd x s x
nN Ni d x i i s x
i ii i
Diffuse Specular
L x K N d L x K R N d
L x K N L x K R N
N p N p
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.
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?
Part 6: Importance Sampling/Russian Roulette
Part 7: D.I.Y. scenes
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.
General TipsUse 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 [email protected]