Photon Mapping
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Photon mapping
A two-pass method
Pass 1: Build the photon map (photon tracing)
Pass 2: Render the image using the photon map
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Building the Photon Map
Photon Tracing
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Rendering using the Photon Map
Rendering
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Photon Tracing
Photon emission • Projection maps • Photon scattering • Russian Roulette • The photon map data structure • Balancing the photon map •
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen What is a photon?
Flux (power) - not radiance! • Collection of physical photons • ⋆ A fraction of the light source power ⋆ Several wavelengths combined into one entity
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Photon emission
Given Φ Watt lightbulb. Emit N photons. Each photon has the power Φ Watt. N
Photon power depends on the number of emitted • photons. Not on the number of photons in the photon map.
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Diffuse point light
Generate random direction Emit photon in that direction
// Find random direction do { x = 2.0*random()-1.0; y = 2.0*random()-1.0; z = 2.0*random()-1.0; while ( (x*x + y*y + z*z) > 1.0 ); }
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Example: Diffuse square light
- Generate random position p on square - Generate diffuse direction d - Emit photon from p in direction d
// Generate diffuse direction u = random(); v = 2* π*random(); d = vector( cos (v)√u, sin (v)√u, √1 u ); −
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Projection maps
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Projection maps
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Surface interactions
The photon is
Stored (at diffuse surfaces) and • Absorbed ( A) or • Reflected ( R) or • Transmitted ( T ) •
A + R + T = 1 .0
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Storing the photon struct photon { float x,y,z; // position char p[4]; // power packed as 4 bytes char phi,theta; // incident direction short flag; // flag used for kd-tree }
Memory overhead: 20 bytes/photon.
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Photon scattering
The simple way:
Given incoming photon with power Φp
Reflect photon with the power R Φp ∗ Transmit photon with the power T Φp ∗ Photon scattering
The simple way:
Given incoming photon with power Φp
Reflect photon with the power R Φp ∗ Transmit photon with the power T Φp ∗ Risk: Too many low-powered photons - wasteful! • When do we stop (systematic bias)? • Photons with similar power is a good thing. •
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Russian Roulette
Statistical technique • Known from Monte Carlo particle physics • Introduced to graphics by Arvo and Kirk in 1990 •
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Russian Roulette
Probability of termination: p Russian Roulette
Probability of termination: p
E X { } Russian Roulette
Probability of termination: p
E X = p 0 { } · Russian Roulette
Probability of termination: p
E X = p 0 + (1 p) { } · − Russian Roulette
Probability of termination: p
E X E X = p 0 + (1 p) { } { } · − · 1 p − Russian Roulette
Probability of termination: p
E X E X = p 0 + (1 p) { } = E X { } · − · 1 p { } − Russian Roulette
Probability of termination: p
E X E X = p 0 + (1 p) { } = E X { } · − · 1 p { } −
Terminate un-important photons and still get the correct result.
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Russian Roulette Example
Surface reflectance: R = 0.5 Incoming photon: Φp = 2 W r = random(); if ( r < 0.5 ) reflect photon with power 2 W else photon is absorbed
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Russian Roulette Intuition
Surface reflectance: R = 0.5 200 incoming photons with power: Φp = 2 Watt
Reflect 100 photons with power 2 Watt instead of 200 photons with power 1 Watt.
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Russian Roulette Example 2
Surface reflectance: R = 0.2 Surface transmittance: T = 0.3 Incoming photon: Φp = 2 W r = random(); if ( r < 0.2 ) reflect photon with power 2 W else if ( r < 0.5 ) transmit photon with power 2 W else photon is absorbed
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Russian Roulette
Very important! • Use to eliminate un-important photons • Gives photons with similar power :) •
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Sampling a BRDF
fr(x, ~ω i, ~ω o) = w1fr, 1(x, ~ω i, ~ω o) + w2fr, 2(x, ~ω i, ~ω o)
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Sampling a BRDF
fr(x, ~ω i, ~ω o) = w fr,d + w fr,s 1 · 2 · r = random() (w + w ); · 1 2 if ( r < w 1 ) reflect diffuse photon else reflect specular
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Specular Reflection
~ ~ ~ dr = di 2~n (~n di) − ·
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen The photon map datastructure
Requirements:
Compact (we want many photons) • Fast insertion of photons • Fast nearest neighbor search • The photon map datastructure
Requirements:
Compact (we want many photons) • Fast insertion of photons • Fast nearest neighbor search •
A left-balanced kd-tree
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen The kd-tree
Introduced by Bentley in 1975 • A multidimensional ``binary'' tree •
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen A left-balanced kd-tree
Post-process:
No pointers (save 40% memory) • Faster search • Recursively split photons along the median of the ``largest'' dimension.
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Photon tracing
Overview:
While (we want more photons) { Emit a photon while (photon hits a surface) { Store photon Use Russian Roulette to scatter photon
} } Build balanced kd-tree
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Rendering
We want a Radiance value, L, per pixel. The photon map stores flux/power. Rendering
We want a Radiance value, L, per pixel. The photon map stores flux/power. Radiance is the differential flux per differential solid angle per differential cross-sectional area:
dΦ2(x, ~ω ) L(x, ~ω ) = dω cos θ dA Rendering
We want a Radiance value, L, per pixel. The photon map stores flux/power. Radiance is the differential flux per differential solid angle per differential cross-sectional area:
dΦ2(x, ~ω ) L(x, ~ω ) = dω cos θ dA
How do we get a radiance estimate from the photon map?
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Radiance estimate
L(x, ~ω ) = fr(x, ~ω ′, ~ω )L′(x, ~ω ′) cos θ′ dω ′ ZΩ Radiance estimate
L(x, ~ω ) = fr(x, ~ω ′, ~ω )L′(x, ~ω ′) cos θ′ dω ′ ZΩ 2 dΦ′ (x, ~ω ′) = fr(x, ~ω ′, ~ω ) cos θ′dω ′ ZΩ dω ′ cos θ′ dA Radiance estimate
L(x, ~ω ) = fr(x, ~ω ′, ~ω )L′(x, ~ω ′) cos θ′ dω ′ ZΩ 2 dΦ′ (x, ~ω ′) = fr(x, ~ω ′, ~ω ) cos θ′dω ′ ZΩ dω ′ cos θ′ dA 2 dΦ′ (x, ~ω ′) = fr(x, ~ω ′, ~ω ) ZΩ dA Radiance estimate
L(x, ~ω ) = fr(x, ~ω ′, ~ω )L′(x, ~ω ′) cos θ′ dω ′ ZΩ 2 dΦ′ (x, ~ω ′) = fr(x, ~ω ′, ~ω ) cos θ′dω ′ ZΩ dω ′ cos θ′ dA 2 dΦ′ (x, ~ω ′) = fr(x, ~ω ′, ~ω ) ZΩ dA n ∆Φ p(x, ~ω p′ ) fr(x, ~ω ′ , ~ω ) ≈ p ∆A Xp=1
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Radiance estimate
L
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen The radiance estimate
Locate the n nearest photons using kd-tree
n ∆Φ p(x, ~ω p′ ) L(x, ~ω ) fr(x, ~ω ′ , ~ω ) ≈ p πr 2 Xp=1 The radiance estimate
Locate the n nearest photons using kd-tree
n ∆Φ p(x, ~ω p′ ) L(x, ~ω ) fr(x, ~ω ′ , ~ω ) ≈ p πr 2 Xp=1
Where the surface is locally flat this is a consistent estimator: Converges to the correct result :)
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Disc filtering Disc filtering
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Filtering
Weight nearby photons higher. Filtering
Weight nearby photons higher. Cone filtering: dp wpc = 1 , − k r
N ∆Φ p(x, ~ω p) wpc Lr(x, ~ω ) fr(x, ~ω p, ~ω ) ≈ πr 2 (1 2 ) Xp=1 − 3k
Also Gaussian filtering
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Caustic from a glass sphere
30000 photons / 50 photons in radiance estimate
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Metalring caustic
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Caustic on a glossy surface
340000 photons / 100 photons in radiance estimate ≈
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Are we done? Are we done?
Works great for caustics :) Are we done?
Works great for caustics :)
But what about other global illumination effects such as color bleeding?
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Direct visualization ofthe radiance estimate
200000 photons / 50 photons in radiance estimate
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Direct visualization ofthe radiance estimate
200000 photons / 500 photons in radiance estimate
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen A practical two-pass method
Observations:
Caustics are difficult to sample (from the eye) • Indirect illumination requires many photons •
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Two photon maps
global photon map caustics photon map
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen The Rendering Equation
Lr(x, ~ω ) = fr(x, ~ω ′, ~ω )Li(x, ~ω ′) cos θ′ dω ′ ZΩx The Rendering Equation
Lr(x, ~ω ) = fr(x, ~ω ′, ~ω )Li(x, ~ω ′) cos θ′ dω ′ ZΩx
Split incoming radiance:
Li = Li,l + Li,c + Li,d direct caustics soft indirect |{z} |{z} |{z} The Rendering Equation
Lr(x, ~ω ) = fr(x, ~ω ′, ~ω )Li(x, ~ω ′) cos θ′ dω ′ ZΩx
Split incoming radiance:
Li = Li,l + Li,c + Li,d direct caustics soft indirect |{z} |{z} |{z} Split the BRDF
fr = fr,d + fr,s diffuse specular |{z} |{z}
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen The Rendering Equation
Lr = fr Li cos θ′ dω ′ ZΩx The Rendering Equation
Lr = fr Li cos θ′ dω ′ ZΩx
= fr Ll cos θ′ dω ′+ direct ZΩx The Rendering Equation
Lr = fr Li cos θ′ dω ′ ZΩx
= fr Ll cos θ′ dω ′+ direct ZΩx
fr,s (Li,c + Ld) cos θ′ dω ′+ specular ZΩx The Rendering Equation
Lr = fr Li cos θ′ dω ′ ZΩx
= fr Ll cos θ′ dω ′+ direct ZΩx
fr,s (Li,c + Ld) cos θ′ dω ′+ specular ZΩx
fr,d Lc cos θ′ dω ′+ caustics ZΩx The Rendering Equation
Lr = fr Li cos θ′ dω ′ ZΩx
= fr Ll cos θ′ dω ′+ direct ZΩx
fr,s (Li,c + Ld) cos θ′ dω ′+ specular ZΩx
fr,d Lc cos θ′ dω ′+ caustics ZΩx
fr,d Ld cos θ′ dω ′ soft indirect ZΩx
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Rendering
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Rendering: direct illumination
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Rendering: specular reflection
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Rendering: caustics
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Rendering: indirect illumination
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen No Importance Sampling
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Importance Sampling
(Using the 50 nearest photons)
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen Lightning
CSE272: Advanced Image Synthesis (Spring 2010) Henrik Wann Jensen