Advanced Computer Graphics

Rendering Equation
Unbiased MC Methods
CMPT 461/770
Advanced Computer Graphics
Torsten Möller
© Machiraju/Möller
Reading
• Chapter 16 of “Physically Based
Rendering” by Pharr&Humphreys
• Chapter 19, 20 in “Principles of Digital
Image Synthesis,” by A. Glassner
© Machiraju/Möller


Direct Light
• General equation of existant radiance:
Lo p,w o   Le p,w o  

S
2
f r p,w o,w i Li p,w i cosi dw i
• Account only for direct light sources, i.e. Replace
Li(p,wi) with Li(p,wi):
Lo p,w o   Le p,w o  
–
–
–
–

S2
f r p,w o,w i Ld p,w i cosi dw i
Most simple form of equation
Somewhat easy to solve! (but a gross simplification)
Kinda what we do in Whitted Ray-tracing
Not too bad - most energy comes from direct lights
© Machiraju/Möller
Direct Light
• MC sampling to solve integral
S f r p,wo,wi Ld p,wi cosi dwi
2
• (A)

N
f r p,w o,w j Ld p,w j cos  i
1

N j1
pw j 
– pick one light as representative for all lights
– Distribute N samples for this light

– Use multiple importance sampling for fr and Ld
– Scale the result by the total number of lights NL
© Machiraju/Möller

Multiple Importance Sampling
N
f r p,w o,w j Ld p,w j cos  i
1

N j1
pw j 
light
light

wo
wo
Weight according to Ld
Weight according to f

© Machiraju/Möller
Direct Light
• (B) uniformly sample all lights
NL

j i

S2
f r p,w o,w i Ld  j   p,w i cos i dw i
– Do (A) for each light source
– Sum the result
– Smarter approach - non-uniform sampling of light
sources: prefer lights with has higher power
© Machiraju/Möller
Light Transport Equation
• Incident radiance effected by all geometry
and scattering within a scene (colour
bleeding)
• Global illumination
o  i  e  a
• Principle
Power
leaving
Power Power
Power
entering emitted absorbed
– Ignore wave optics
– Energy balance (radiance is in equilibrium)

© Machiraju/Möller
Light Transport Equation
o  i  e  a
o  e  i  a 
Lo  p,w o   Le  p,w o  


S2
f r p,w o ,w i Li p,w i cos  i dw i
• If no participating media - express incoming in
Lo  p,w 
terms of outgoing radiance:
Li p,w   Lo t p,w ,w


• Need to solve for L (only one unknown)
Lp,w o   Le p,w o  

S2
Li  p,w 
f r p,w o,w i Lt p,w i ,w i cosi dw i
© Machiraju/Möller


Example - lambertian light
•
•
•
•
•

One spherical light source on the outside
No scene geometry
Lambertian BSDF, fr=c
Emitted radiance Le in constant
Lp,w o   Le  c 
L

H2
Lt p,w i ,w i cosi dw i
Lt p,w i ,w i cosi dw i
is the same, no
matter which point on the light. Hence:
H2
Lp,w o   Le  cL
© Machiraju/Möller
Example cont.
• Let’s solve the last L p,w o   Le  cL
 Le  c Le  cL
equation a little weirdly:


 Le  c Le  c Le  c ...

  Le c 
i
i 0
• These are basically the number of bounces
Le
Le
L
p,
w


 o
• rhh is the reflectance
1 c 1 rhh

• von Neumann series - principle solution method

© Machiraju/Möller
Example - direct lighting
• Using recursion for direct lighting:
Lp,w o   Le p,w o    f r  p,w o ,w i Ld t  p,w i ,w i cos i dw i
S
Ld t  p,w i ,w i   Le t p,w i ,w i 
  f r t p,w i ,w i ,wLd t t  p,w i ,w,wcos dw
S
2
2
• The last term is being ignored; represents
secondary (bounced) light
© Machiraju/Möller
LTE - Geometric Formulation
• Expressing LTE in terms of geometry
within the scene
p
Lp,w   Lp p
f p,w o ,w i   f p p p


wo
p
wi
 p
• Replacing the integrand (dwi)with an area

integrator over the whole scene
geometry

cos
and remembering: dw i 
2
p p
• V p  p - visibility term (either one or zero)

© Machiraju/Möller

LTE - Geometric Formulation
• Geometry coupling term
Gp  p  V p  p
cos cos 
p p
2
• New (geometric) formulation
of the Light Transport Equation
 (LTE)
Lp p  Le p p 
p
p
wo
wi
 p
 f p p pLp pGp pdAp
r

• Randomly pick points in the scene andcreate a

path vs. (previously)
A
• randomly pick directions over a sphere
© Machiraju/Möller
LTE - Geometric Formulation
• Recursive evaluation
L p1  p0   Le p1  p0 
  A Le p2  p1  f p2  p1  p0 Gp2  p1 dAp2 
  Le p3  p2  f p3  p2  p1 Gp3  p2 
A
f p2  p1  p0 Gp2  p1dAp2 dAp3 
...

f  p3  p2  p1 

p2
p0


© Machiraju/Möller
Gp2  p1
p1

G p3  p2 
f 
p2  p1  p0 
p3
LTE - Geometric Formulation
• compact formulation:

L p1  p0    P pi 
i1
• For a path pi  p0 p1...pi
• Where p0 is the

camera and pi is
p0
a 
light source

© Machiraju/Möller

f  p3  p2  p1 
p2

Gp2  p1
p1

G p3  p2 
f 
p2  p1  p0 
p3

LTE - Geometric Formulation
• with:
Ppi  
  ...  L p  p Tp dAp ...dAp 
e
A A
i
i1
i
2
i
A
i1
• Where Tpi    f p j 1  p j  p j1Gp j 1  p j 
j1
•Is called the throughput
• Special case:
f p  p  p 

p2
P  p1  Le p1  p0 
3
p0

© Machiraju/Möller

1
G p3  p2 

Gp2  p1
p1

2
f 
p2  p1  p0 
p3

Specular distributions
• Again - handle with care (e.g. point light):
P  p2  
 L p
e
2
 p1  f p2  p1  p0 Gp2  p1 dAp2 
A

 plight  p2 Le p2  p1 
pplight 
f  p2  p1  p0 G p2  p1 
 Le plight  p1 f plight  p1  p0 Gplight  p1 
• E.g. Whitted ray
tracing only uses
specular BSDF’s
plight
p0

© Machiraju/Möller

Gplight  p1
p1 f p
light

 p1  p0 
Solving the LTE
• Many different algorithms proposed to deal
with  Pp 
• Most energy in the first few bounces:

i
i 0


L p1  p0   P p1   P  p2    P pi 
i 3
• P  p1  emitted radiance at p1
• P p2 one bounce to light (direct lighting)

© Machiraju/Möller
Solving the LTE
• Simplify according to small and large light
sources: Le  Le,s  Le,l
P  pi     ...  Le  pi  pi1T  pi dA p2 ...dApi 
A A

A
  ...  L p
i
 pi1 T pi dAp2 ...dA pi 
 ...  L p
 pi1 T  pi dA p2 ...dApi 
e,s
A A

A A
A
e,l
i
A
• Can be handled separatly (different number
of samples)

© Machiraju/Möller
Solving the LTE
• Similarly, we can split BxDF into delta and
non-delta distributions:
f  f   f 
i1
T pi     f   f Gp j 1  p j 
j1
• This creates many factors that cannot be
ignores

© Machiraju/Möller

Measuring over a pixel
• Integrating over pixel j:
Ij 

A film


A film
S2
W e p film,w Li p film,w cos dwdAp film 
S2
W e p0  p1Li p1  p0 Gp1  p0 dAp0 dAp1
• Where We is the filter function around a
pixel:

We p0  p1  f j p0  tp0,wcamera p0  p1

© Machiraju/Möller


Integrating over a pixel
• And hence the integral:
Ij 

A film


S2
W e  p0  p1 Li  p1  p0 G p1  p0 dA p0 dA p1 

i1 A film

 
S2
W e  p0  p1 P  pi G p1  p0 dA p0 dA p1 
 ...  W p
i1 A A
e
0
 p1 T pi Le pi1  pi dAp0 ...dA pi 
A
• A - light bounces around until it hits the camera
• B - a quantity from the sensor bounces around and
only makes a contribution if it hits a light
© Machiraju/Möller
Path Tracing
•
Kajiya 1986; solution to

L p1  p0    P pi 
i1
A. How to deal with infinite sum?
B. For a particular i - how to generate one or

more paths to estimate P  pi 
© Machiraju/Möller
A) Infinite Sum
• In general => the longer the path the less the
impact
• Use Russian Roulette after a finite number
of bounces
– always compute first few terms
– Stop after that with probability q

1
L p1  p0   P p1   P  p2   P p3  
P  pi 

1 q i 4
© Machiraju/Möller
A) Infinite Sum
• Use probability qi after each pi

1 
1 
1
Lp1  p0  
Pp3   ...
Pp1 

Pp2  
1 q1 
1 q2 
1 q3


© Machiraju/Möller
B) Path Generation
• Pick a surface in the scene at random (I.e.
uniform probability distribution):
pi 
Ai
 Aj
j
• Pick a point on this surface at random
(uniform) with probability 1/Ai

• Overall probability
of picking a random
surface point in the scene:
Ai
1
1
pA  pi  
 
 A j Ai  A j
j
© Machiraju/Möller
j
B) Path Generation
• This is repeated for each point on the path
• Last point should be sampled on a light source
• If we know things about the scene (which objects
are contributing most indirect lighting to the
scene) we can sample more smartly
• Problems:
– High variance - only few points are mutually visible
– Incorrect integral - for delta distributions
© Machiraju/Möller
B) Incremental Path
Generation
• For path pi  p0 p1...pi
– At each pj find pj+1 according to BSDF
– At pi-1 find pi by multiple importance sampling
of BSDF and Ld

• This algorithm distributes samples
according to solid angle (w) instead of area
• Hence prob. Distribution pA needs to be
2
adjusted:
pi  pi1
pA  pi   pw
cos  i
© Machiraju/Möller
B) Incremental Path
Generation
• MC estimator:
Le pi  pi1i1 f p j 1  p j  p j1cos i 




pA pi   j1
pw p j 1  p j 

• Implementation:
 – Re-use path pi1 for new path pi
• Introduces correlation, but speed makes up
for it


© Machiraju/Möller
Path Tracing
© Machiraju/Möller
Path Tracing
1024 samples per pixel
8 samples per pixel
Direct lighting only
© Machiraju/Möller
Pure Path Tracing
• Best for big
luminaires.
• If lights small,
few hits and
large variance.
© Machiraju/Möller
Results
• Objects are gray,
except for
spheres and base.
– Color bleeding
– Caustics
© Machiraju/Möller
Results
256 x 256 image
Ray Traced
Path Traced
(no ambient)
533 minutes
401 minutes
© Machiraju/Möller
Light scattered
by sphere


Bi-directional path tracing
•
Compose one path p from two paths
p1 p2 ...pi started at the camera p0 and
q j q j1...q1 started at the light source q0
p  p1 p2 ...pi ,q j q j1 ...q1

Modifications for efficiency:
–
–
•
a) Use all i+j paths:
b) For all paths p1 p2 ...pi,q1
 replace q1 with direct
lighting computation
like normal path tracing

© Machiraju/Möller
p1 ...pi ,q j ...q1
p1 ...pi ,q j ...q1
p1 ...pi1,q j ...q1
p1 ...pi ,q j1 ...q1
p1 ...pi2 ,q j ...q1
p1 ...pi ,q j1 ...q1
M
M
p1,q j ...q1
p1 ...pi ,q1
Bi-directional path tracing
• When useful?
– Light sources difficult to reach
– Specific BSDF evaluations (caustics)
© Machiraju/Möller
Bi-direct RT : Pseudo-Code
© Machiraju/Möller
Pure Bi-Directional: Analysis
• Advantages:
– Each ray cast contributes to many paths
– Building from both ends can catch difficult cases
• All specular paths
• Caustics
– Extends to participating media (anisotropic,
heterogeneous)
• Disadvantages:
– Still using lots of effort to catch slow varying diffuse
components
– May not sample difficult to find paths
– Does allow for much noise to be present
© Machiraju/Möller
Still Tough Cases
• Caustics
– How do you know which
direction to cast eye rays to
reach the interesting light?
• Bleeding
– How do you know which
rays to reflect to reach the
interesting parts of diffuse
reflections?
© Machiraju/Möller
MC Algorithms Revisited
• Provide ability to sample light transport
paths.
• MC algorithms studied so far sample a
function to compute the value of an integral.
• Problems:
– Many of the paths are unimportant.
– Pure Bi-Directional Path algorithm does not
reject.
– It may weigh down some paths.
© Machiraju/Möller
Metropolis’s Idea
• Circa 1953
• Generate a distribution of samples proportional to
the unknown function
• For rendering –
– sample image with ray density proportional to radiance
– random walk through path space
• Eric Veach’s PhD thesis and Veach&Guibas paper
in Siggraph introduced work of Metropolis to
Graphics
© Machiraju/Möller
Why Does It Make Sense ?
• In the final image:
– More detail in brighter areas
– Value of a pixel will be proportional to the
number of times it was sampled in a path
© Machiraju/Möller
Metropolis Light Transport
• Generate a random walk x  p0 p1...pi
through path space
• For each path deposit a constant amount of
energy at the corresponding
pixel

• Obtain desired image by distributing paths
according to image contribution
 Metropolis sampling
© Machiraju/Möller
Metropolis Sampling
• Propose a mutation y of current path x
• Compute acceptance probability
 f ( y )T ( y  x ) 
 ( y , x )  min 1,

 f ( x )T ( x  y ) 
• Choose y as new sample if   
•
 Samples are correlated
•
 we can exploit coherence
© Machiraju/Möller
Metropolis Sampling
• Where f (y ) is the image contribution
function (contribution made to the image by
light flowing through y )
• T(x  y ) tentative transition function 
probability of y given x

© Machiraju/Möller
Metropolis light transport
pixel
Le
Mutations
© Machiraju/Möller
MLT: Pseudo-Code
© Machiraju/Möller
Mutation Strategies
• Bidirectional Mutations
– large changes to the current path
– ensures ergodicity
• Perturbations
– high acceptance probability
– changes to image location
– low cost
Scattering Perturbations
Propagation Perturbations
© Machiraju/Möller
Sensor Perturbations
Caustic Perturbations
Bidirectional Mutations
• Given a path x  p0 p1...pi
1. Choose a random subpath to delete.
2. Add random numbers of new vertices to
the new
 interior endpoints of X.
3. Try to connect up the two innermost
vertices.
4. Test for acceptance of the new path.
© Machiraju/Möller
Mutations – Step 1
x1

x0
x2
© Machiraju/Möller
Mutations – Step 1
• Random subpath to delete.
• Weigh probability so that smaller subpaths
are chosen more frequently.
x1

x0
x2
© Machiraju/Möller
Mutations – Step 2
• Add random numbers of new vertices.
• Choose number to add from a distribution
centered around old number.
• Choose where to put the break (i.e. how
many to add at end of first segment vs.
beginning of last segment).
• Add each vertex by sampling a direction
according to a BRDF, and then casting a
ray.
© Machiraju/Möller
Mutations – Step 2
• Chose to add 2 vertices, with the break
between them.

x0
x2
© Machiraju/Möller
Mutations – Step 3
• Connect two innermost vertices
• Test if two new endpoints are visible
• If the path is obstructed, reject the mutation
x1

x0
x3
x2
© Machiraju/Möller
Mutations – Step 4
• Test for acceptance of the new path Y over
old path X.
 f ( y )T ( y  x ) 
• Use
 ( y , x )  min 1,

 f ( x )T ( x  y ) 
• Note that much of this can be precomputed.
© Machiraju/Möller
Good Mutations
• Don’t make changes
that are too small
• Don’t get stuck

© Machiraju/Möller
Perturbations
• Are needed when bidirectional mutations
will nearly always be rejected.
• When there are small regions of the path
space in which paths contribute much more
than average.
– Lenses
– Caustics
• Smaller mutations keep them within high
contribution region
© Machiraju/Möller
Propagation Perturbations
medium
image plane
eye
© Machiraju/Möller
light source
Perturbations
• Move the pixel location (i.e. the path’s endpoint)
by a random distance in a random direction.
• Recast rays through all the specular bounces so
that it retains the same length.
• Mutation strategy depends on what is encountered
• For example in the caustic LS+DE case make
small change in ray connecting the diffuse and
specular surface
© Machiraju/Möller
Caveat
• Run several copies of the algorithm in parallel.
– Helps to remove startup bias.
– Helps to test for convergence.
• Ignore the first several path samples.
– Helps to remove startup bias.
• Don’t bother with MLT for the direct lighting in
an image.
– Standard techniques for direct lighting usually provide
better quality at lower cost.
– This way MLT can devote more effort to the indirect
lighting.
© Machiraju/Möller
© Machiraju/Möller
Results
• Light for this
example comes
only through
crack in doorway
© Machiraju/Möller
Results
• There are specific
mutations to
capture caustics.
© Machiraju/Möller
Good For 
• Portions of space where light comes
through
• hole in the wall kinds 
– mutations will explore new paths once it finds a
path through the hole
– Bi-directional
and Plain Path
Tracing use
random directions
© Machiraju/Möller
Not Good For 
•
•
•
•
Cornell Box scenes will not benefit
Caustics will certainly help.
Too many holes does not help
Also caustics from mirror reflections
© Machiraju/Möller
Results
© Machiraju/Möller
Results
© Machiraju/Möller
Results
© Machiraju/Möller