Sie sind auf Seite 1von 54

path tracing

computer graphics path tracing 2010 fabio pellacini, william kerr 1


path tracing
Monte Carlo algorithm for solving the rendering
equation

computer graphics path tracing 2010 fabio pellacini, william kerr 2


solving rendering equation

advantages
predictive simulation
can be used for architecture, engineering,
photorealistic
if simulation if correct, images will look real
disadvantages
(really) slow
simulation of physics is computationally very expensive
need accurate geometry, materials and lights
otherwise just a correct solution to the wrong problem

computer graphics path tracing 2010 fabio pellacini, william kerr 3


rendering equation

L(x ) Le (x )
L(x ) (x, ) cos d
x

[Bala]
x x

L(x ) Le (x ) L( x )
computer graphics path tracing 2010 fabio pellacini, william kerr 4
basic path tracing

need to evaluate radiance at x in direction


L(x ) Le (x ) Lr (x )

determine visible point


x r (e )

look up emission

[Bala]
Le (x )

computer graphics path tracing 2010 fabio pellacini, william kerr 5


basic path tracing

need to evaluate
Lr (x ) L(x ) (x, ) cos(N x , )d
x

use Monte Carlo estimation


1 N L(x i ) (x, i ) cos(N x , i )
Lr (x )
N i1 p(i )

computer graphics path tracing 2010 fabio pellacini, william kerr 6


basic path tracing

generate random direction i with p(i)


1 N L(x i ) (...) cos(...)
Lr
N i1 p(i )

evaluate BRDF
evaluate cosine
evaluate L(x i )

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 7
basic path tracing

need to evaluate
L(x i )
determine visible point from x in direction i
r (x i )

in vacuum
L(x i ) L(r (x, i ) i )

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 8
basic path tracing

need to evaluate
L(r (x, i ) i )
recursively execute procedure

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 9
russian roulette

when to stop recursion?


light bounce infinitely in the environment
but every bounce has less energy
in many cases 3-4 bounces are enough

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 10
russian roulette

stop after k bounces


introduces bias (consistent error) in the solution
need to make k large to capture all cases

Monte Carlo strategy (Russian Roulette) as stopping


criterion
pick a probability with which to stop the path
at each intersection, test the path
correct the radiance estimator accordingly

computer graphics path tracing 2010 fabio pellacini, william kerr 11


russian roulette
1 1 f ( x) P f ( y / P)
I f ( x)dx Pdx dy P 1
0 0 P 0 P

P f ( y / P)
I RR dy

[Dutr, Bekaert, Bala]


0 P
P f ( y)
dy
0 P

computer graphics path tracing 2010 fabio pellacini, william kerr 12


russian roulette



f ( y / P)
yP
y ~1 f ( y) P

0 yP

1 P f ( y / P)
E[ f ( y )] f ( y ) p( y )dy dy I
0 0 P

1 N f ( xi )
E[ f ( x)] [ f ] [ f ]
N i1 p( xi )
reminder:
2 [ x] E[ x 2 ] E[ x]2
computer graphics path tracing 2010 fabio pellacini, william kerr 13
russian roulette

if f is a recursive integral, only stop with


probability 1 P
but weight back the radiance LRR L /(1 )

example: path tracing with 0.1


only 1 chance in 10 the ray will continue
estimated radiance of the ray multiplies by 10
intuition: instead of shooting 10 rays, shoot 1 but
weight its contribution 10 times

computer graphics path tracing 2010 fabio pellacini, william kerr 14


russian roulette

how to choose the probability?


small fixed value: longer paths
slow but accurate
big fixed value: shorter paths
fast but inaccurate
proportional to integral of reflected light
adapts to material properties
darker patches will statistically shorten paths
exactly like in physics

computer graphics path tracing 2010 fabio pellacini, william kerr 15


basic path tracing pseudocode
computeImage()
foreach pixel (i,j)
estimatedRadiance[i,j] = 0
for s = 1 to #viewSamples
generate Q in pixel (i,j)

[Dutr, Bekaert, Bala]


theta = (Q E)/|Q-E|
x = trace(E,theta)
estimatedRadiance [i,j] +=
computeRadiance(x,-theta)
estimatedRadiance [i,j] /= #viewSamples

computeRadiance(x, theta)
estimatedRadiance = basicPT(x, theta)
return estimatedRadiance
computer graphics path tracing 2010 fabio pellacini, william kerr 16
basic path tracing pseudocode

basicPT(x, theta)
estimatedRadiance = Le(x, theta)
if(not absorbed) // russian roulette
for s = 1 to #radianceSamples
psi = generate random dir on hemisphere

[Dutr, Bekaert, Bala]


y = trace(x, psi)
estimatedRadiance +=
basicPT(y,-psi) * BRDF(x,psi,theta) *
cos(Nx,psi) / pdf(psi)
estimatedRadiance /= #paths
return estRadiance/(1-absorption)

computer graphics path tracing 2010 fabio pellacini, william kerr 17


basic path tracing intuition

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 18
basic path tracing intuition

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 19
basic path tracing performance

1 sample 16 samples 256 samples

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 20
monte carlo vs. deterministic integration

Monte Carlo Deterministic

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 21
next event estimation

in basic path tracing


if path does not hit a light, its radiance is 0
unlikely to hit a light by randomly picking dirs.

next event estimation


want to directly sample light sources
by splitting direct and indirect illumination estimation
two separate Monte Carlo processes
by using area formulation for direct illumination
by using hemispherical formulation for indirect

computer graphics path tracing 2010 fabio pellacini, william kerr 22


direct and indirect illum. formulation

L(x ) Le (x )
L(x ) (x, ) cos d
x

[Bala]
x x

L(x ) Le (x ) L( x )
computer graphics path tracing 2010 fabio pellacini, william kerr 23
direct and indirect illum. formulation

L(x ) Le (x ) Lr (x )

[Bala]
L( x ) Le (x ) Lr (x )

computer graphics path tracing 2010 fabio pellacini, william kerr 24


direct and indirect illum. formulation

Lr (x ) Le (x ) (...) cos d
x

Lr (x ) (...) cos d
x

Ld (x ) Li (x )

computer graphics path tracing 2010 fabio pellacini, william kerr 25


direct illum. hemisphere sampling

Ld (x ) Le (x ) (...) cos d
x

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 26
direct illum. area sampling

Ld (x ) Le (y yx) (...)G(x, y )V (x, y )dAy


ylights

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 27
indirect illum. hemisphere sampling

Li (x ) Lr (x ) (...) cos d
x

discard Le
if ray hits light

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 28
indirect illum. recursive evaluation

Li (x ) Lr (x ) (...) cos d
x

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 29
next event estimation performance

without with

[Bala]
16 samples

computer graphics path tracing 2010 fabio pellacini, william kerr 30


next event estimation performance

1 sample 4 samples

[Bala]
16 samples 256 samples

computer graphics path tracing 2010 fabio pellacini, william kerr 31


direct illumination one light

Ld (x ) Le (y yx) (...)G (x, y )V (x, y )dAy


ylight

1 N Le (y i y i x) (...)G (x, y i )V (x, y i )


Ld (x )
N i1 p(y i )

depends on
emitted radiance distribution Le
how to pick points y on the light
how many points to use
number of shadow rays

computer graphics path tracing 2010 fabio pellacini, william kerr 32


direct illumination one light

each light type has its own physical model


angular distribution defines different light types
flood, fill, spot, ect

simplest model: emitted radiance is a constant


Le (y ) Le

computer graphics path tracing 2010 fabio pellacini, william kerr 33


direct illumination one light

uniform sampling of light area

1
p(y )
AS
simply sample that [0,1] square and rescale
works fairly well in practice
slightly better techniques exists tough

computer graphics path tracing 2010 fabio pellacini, william kerr 34


direct illumination many lights

Ld (x ) Le (y yx) (...)G(x, y )V (x, y )dAy


ylights

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 35
direct illumination many lights

Ld (x ) Le (y yx) (...)G(x, y )V (x, y )dAy


ylights

how to allocate samples between different lights


various techniques, some quite advanced

computer graphics path tracing 2010 fabio pellacini, william kerr 36


direct illumination many lights

split samples uniformly between lights


same as M light integrals with previous sampling
M
Ld (x ) Le (y yx) (...)G (x, y )V (x, y )dAy
ylight
j 1 j

M N /M Le (...) (...)G (x, y ij )V (x, y ij )


Ld (x )
j 1 i 1 p(y ij )
simple but inefficient
would like to weight more brighter lights
wont cover in this class

computer graphics path tracing 2010 fabio pellacini, william kerr 37


indirect illumination

Li (x ) Lr (x ) (...) cos d
x

1 N Lr (x ) (...) cos
Li (x )
N i 1 p( )
depends on how to sample the hemisphere
uniform distribution
importance sampling: pick p to match integral
cosine distribution
BRDF distribution
BRDF*cosine distribution

computer graphics path tracing 2010 fabio pellacini, william kerr 38


indirect illumination uniform dist.

1
p( )
2

2 N
Ld (x )
N i1
Lr (x ) (...) cos

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 39
indirect illumination cosine dist.

cos
p( )

N
Ld (x )
N
L (x ) (...)
i 1
r

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 40
indirect illumination BRDF Dist.

p() ~ (...)

1 N
Ld (x ) Lr (x ) cos
N i 1

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 41
indirect illumination BRDF*Cosine Dist.

p() ~ (...) cos


N
1
Ld (x )
N
L (x )
i 1
r

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 42
importance sampling performance

without with

[Bala]
computer graphics path tracing 2010 fabio pellacini, william kerr 43
pt pseudocode pixel sampling
computeImage()
foreach pixel (i,j)
estimatedRadiance[i,j] = 0
for s = 1 to #viewSamples
generate Q in pixel (i,j)
theta = (Q E)/|Q-E|

[Dutr, Bekaert, Bala]


x = trace(E,theta)
estimatedRadiance [i,j] +=
computeRadiance(x,-theta)
estimatedRadiance [i,j] /= #viewSamples

computer graphics path tracing 2010 fabio pellacini, william kerr 44


pt pseudocode radiance estimation
computeRadiance(x,theta)
estimatedRadiance = Le(x,theta)
estimatedRadiance += directIllumination(x, theta)
estimatedRadiance += indirectIllumination(x, theta)
return estimatedRadiance

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 45
pt pseudocode direct illumination
directIllumination(x,theta)
estimatedRadiance = 0
for s = 1 to #shadowRays
k = pick random light
y = generate random point on light k
psi = (x-y) / |x-y|

[Dutr, Bekaert, Bala]


estimatedRadiance += Le_k(y,-psi) *
BRDF(x,psi,tetha) *
G(x,y) * V(x,y) /
(p(k)*p(y|k))
estimateRadiance /= #shadowRays
return estimatedRadiance

computer graphics path tracing 2010 fabio pellacini, william kerr 46


pt pseudocode direct illumination UL
directIllumination(x,theta)
estimatedRadiance = 0
for k = 1 to #lights
for s = 1 to #shadowRays / #lights
y = generate random point on light k
psi = (x-y) / |x-y|

[Dutr, Bekaert, Bala]


estimatedRadiance += Le_k(y,-psi) *
BRDF(x,psi,tetha) *
G(x,y) * V(x,y) / p(y)
estimateRadiance /= #shadowRays
return estimatedRadiance

computer graphics path tracing 2010 fabio pellacini, william kerr 47


pt pseudocode indirect illumination
indirectIllumination(x,theta)
estimatedRadiance = 0
if(not absorbed) // russian roulette
for s = 1 to #indirectSamples
psi = generate random dir on hemisphere
y = trace(x, psi)

[Dutr, Bekaert, Bala]


estimatedRadiance +=
computeRadiance(y,-psi) *
BRDF(x,psi,theta) *
cos(Nx,psi) / pdf(psi)
estimatedRadiance /= #indirectSamples
return estimatedRadiance /(1-absorption)

computer graphics path tracing 2010 fabio pellacini, william kerr 48


beyond path tracing
bidirectional techniues

computer graphics path tracing 2010 fabio pellacini, william kerr 49


path tracing

perfectly accurate, but slow to converge


noise remains in the image for a long time

intuition: if there are bright reflections, we cannot


sample them directly
curvy, reflective/refractive surfaces + light =>
focused light (caustics)

idea: shoot paths from the eye and from the light
eye paths: work well for reflections
light paths: pick up secondary sources
in reality very complex
computer graphics path tracing 2010 fabio pellacini, william kerr 50
bidirectional path tracing

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 51
bidirectional path tracing

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 52
photon mapping

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 53
photon mapping

[Dutr, Bekaert, Bala]


computer graphics path tracing 2010 fabio pellacini, william kerr 54

Das könnte Ihnen auch gefallen