Global Illumnaton Computer Graphcs COMP 770 (236) Sprng 2007 Instructor: Brandon Lloyd 3/26/07 1
From last tme Robustness ssues Code structure Optmzatons Acceleraton structures Dstrbuton ray tracng ant-alasng depth of feld soft shadows moton blur 3/26/07 2
Today s topcs Renderng equaton Path tracng Photon mappng Radosty 3/26/07 3
Global Illumnaton Technques The Renderng Equaton theoretcal bass for lght transport Path Tracng attempts to trace lght paths to the eye Photon Mappng deposts lght energy from the source for later collecton Radosty Computes equlbrum for dffuse nterreflectons 3/26/07 4
Kajya s Renderng Equaton ( ρ ) I( xx, ) g( xx, ) e( xx, ) ( xx,, x )I( x, x )dx = + I(x,x ) Lght transported at x from x g(x,x ) geometry (vsblty) term fracton of lght from x that reaches x e.g. shadows, occluson e(x,x ) emssve term lght emtted by x toward x e.g. lght sources ρ(x,x,x ) reflectvty fracton of ntensty ncdent at x from x reflected n the x drecton 3/26/07 5
Soluton Methods I = ge + gr(i) R( ) Integrals are lnear operators Reflected ntensty s twce the power f the ncdent radance s twce the power (homogenety) R(cI) = cr(i) Reflected ntensty from two lght sources s equal to the sum of the ntenstes reflected from each (superposton) R(I 1 + I 2 ) = R(I 1 ) + R(I 2 ) Solve for ntensty I (1 gr)i = ge I= (1 gr) -1 ge ( ρ ) I( xx, ) g( xx, ) e( xx, ) ( xx,, x )I( x, x )dx = + I = ge + grge + grgrge + grgrgrge +... 1 1+ A + A A 1 1 A A A A A A A 2 2 3 2 A 3 2 + One bounce; Two bounces drect llumnaton 3/26/07 6
Grammar for Lght Paths L Lght source E Eye D Ideal dffuse reflector ρ(x,x,x ) = ρ( x j,x,x ) for all and j In general, any nteracton where lght s scattered across hemsphere S Ideal specular reflector Mrror Reflecton, Ideal Refracton ρ(x,x,x ) = δ(ang(x,x ) ang(x,x )) In general, any nteracton where lght s reflected n a sngle drecton Regular expressons X* (0 or more) X+ (1 or more) X? (0 or 1) (X Y) (X or Y) 3/26/07 7 D S
Paths OpenGL L(D S)E I = ge + gde (no shadows) I = ge + gdge (shadow buffer) Ray tracng LD?S*E I = ge + g(sg)*dge Radosty LD*E I = g(dg)*e 3/26/07 8
Energy Transport L = Radance power per unt projected area perpendcular to the ray, per unt sold angle n the drecton of the ray (W m - 2 sr -1 ) dω dω Fundamental unt of lght transport Invarant along ray da 1 da 2 da da L 1 L 2 dω 2 dω 1 L = 2 d Φ (n r)dadω = 2 d Φ cos θdadω Φ= Radant Flux (Photons/sec - W) dφ/da = Irradance (from emtter W/m 2 ) dφ/da = Radosty (from surfaces W/m 2 ) dφ/dω = Radant Intensty (W/sr) Ths term factors n the projected area of the nfntesmal surface patch along the transport drecton 3/26/07 9
Radance Form of Renderng Equaton L( x, ω) L ( x, ω) f( x, ω, ω )G( x, x )L( x, ω )da = + e r Ths s the same equaton that we saw before, but the ntegraton doman s over orented nfntesmal surface patches rather than ponts ω θ x θ x ω Surface BRDF cosθ cosθ G( xx, ) = 2 V( xx, ) x x V(x, x ) vsblty term 1 f vsble 0 f occluded 3/26/07 10
Kajya s Path Tracng At each ht, Cast one random reflected or refracted ray and weght result based on specular, dffuse, and transmsson coeffcents Termnate path when contrbuton s mperceptble (harder than you mght thnk wth hgh dynamc range lght sources) Augment wth mportance samplng (add one random ray to a lght) Cast a large constant number of rays per pxel (40-1000) 3/26/07 11
Results 256 x 256 mage Ray Traced Path Traced Lght scattered 401 mnutes 533 mnutes by reflectve sphere 3/26/07 12
Results All objects are gray, except for spheres and base. Color bleedng Caustcs 3/26/07 13
Path Tracng Postulates that even for ray tracng, followng one random path statstcally s better, than computng a *bushy* ray tree and ntegratng the results. Why? Largest contrbuton from frst ray, and ths approach ncludes more frst-ray samples as a fracton of the total. Key Issues Samplng s extremely mportant Need to be careful about proporton of reflecton, refracton, and shadow rays. Want to avod basng the results. An unbased samplng has the same mean as the fnal result, only the varance (nose) s reduced by samplng Current Methods B-drectonal path tracng (Lafortune and Veach) Metropols (Veach & Gubas) Path trace some, then carefully perturb exstng paths rather than generatng new ones (substantal beneft far from the root) 3/26/07 14
Pure Path Tracng Traces many rays forward from the eye randomly choosng reflecton drectons and weghts them accordng to the BRDF 3/26/07 15
Pure Path Tracng Best for large lght sources. Small lghts lead to few hts and large varance. 3/26/07 16
Wth Shadow Ray to Lghts Adds n Dge terms at each bounce 3/26/07 17
Wth Shadow Ray to Lghts Small lghts OK. Best for specular surfaces. 3/26/07 18
Lght Tracng Traces many rays backward from the lght source, and n a second pass ntegrates n vewng drecton 3/26/07 19
Lght Tracng Small lghts OK. Best for caustcs. 3/26/07 20
B-Drectonal Path Tracng Traces some rays forward from the eye, and others backwards from the lght source 3/26/07 21
B-Drectonal Path Tracng Slow. Must sample carefully Best for caustcs. 3/26/07 22
Bdrectonal Path Tracng Path Tracng Bdrectonal Path Tracng 3/26/07 23
Caustcs Monte-Carlo ray tracng handles all paths of lght L(D S)*E, but not equally well Has dffculty samplng LS*DS*E paths, e.g. refracton of a caustc Path tracng would need a very lucky frst ht Bdrectonal ray tracng can fnd caustc, but reflecton of caustc stll needs lucky frst ht durng path tracng Metropols lght transport can fnd a caustc path, but would need lucky perturbaton to fnd ts reflecton 3/26/07 24
Photon Mappng Photon Mappng has become the most practcal soluton for accurate global llumnaton models Jensen EGRW 95, 96 Smulates the transport of ndvdual photons Photons emtted from lght sources Photons bounce off of specular surfaces Two passes Pass 1: Photons *deposted* on dffuse surfaces, bounced off, and re-deposted - Held n a 3-D spatal data structure - Surfaces need not be parameterzed Pass 2: Photons collected by path tracng from eye 3/26/07 25
Why Map Photons? Hgh varance n Monte-Carlo renderngs results n nose Collecton of deposted photons nto a photon map (a 3-D spatal data structure) provdes a flux densty estmate Flux samples can be nterpolated easer than path samples, because flux generally vares slowly over surfaces (lower frequency) Introduces bas, whch decreases as the number of photons ncrease 3/26/07 26
Why Map Photons? And, oh yeah, t s a lot faster The The scene scene on on the the left left contans contans glossy glossy surfaces, surfaces, and and was was rendered rendered n n 50 50 mnutes mnutes usng usng photon photon mappng. mappng. The The same same scene scene took took 6 hours hours for for render render wth wth Radance, Radance, a a renderng renderng system system that that uses uses radosty radostyfor for dffuse dffuse reflecton reflecton and and path path tracng tracng for for glossy glossy reflecton. reflecton. 3/26/07 27
What s a Photon? A photon p s a partcle of lght that carres flux Φ p (x p, ω p ) Power: Φ p magntude (n Watts) and color of the flux t carres, stored as an RGB trple Poston: x p locaton of the photon Drecton: ω p the ncdent (ncomng) drecton ω used to compute rradance Photons vs. rays Photons propogate radant flux Rays gather radance ω p You must ntegrate flux over sold angle and projected area to convert t to radance Φ p 3/26/07 28 x p
Sources Pont source Photons emtted unformly n all drectons Power of source (W) dstrbuted evenly among photons Flux of each photon equal to source power dvded by total # of photons For example, a 100W lght bulb that sent out 100K photons, would have each carry a flux Φ of 1 mw Photons sent out once per smulaton as a preprocess. Can be reused f only vewpont changes. 3/26/07 29
Russan Roulette Arvo & Krk, SIGGRAPH90 Reflected flux only a fracton of ncdent flux. We could attenuate the flux of our photon based on the reflectance coeffcent, and send t off n a random drecton. After several reflectons, spendng a lot of tme keepng track of very lttle flux Instead, completely absorb some photons and completely reflect others at full power. Spend tme tracng fewer full power photons. Probablty of reflectance s the reflectance ρ. Probablty of absorpton s 1 ρ.? ρ = 60% 3/26/07 30
Mxed Surfaces If surfaces have specular and dffuse components ρ d dffuse reflectance ρ s specular reflectance ρ d + ρ s < 1 (conservaton of energy) Let ζ be a unform random value from 0 to 1 If ζ < ρ d then reflect dffuse (send off n a random drecton) Else f ζ < ρ d + ρ s then reflect specular (send off *near* reflected drecton) Otherwse absorb ρ d = 50% ρ s = 30% 3/26/07 31
Storng Photons Uses a Kd-tree (axs-algned varant of BSP tree) 2-D parttons are lnes 3-D parttons are planes Axs of parttons alternates wrt depth of the tree Average access tme s O(log n) Worst case O(n) when tree s severely lopsded Need to mantan a balanced tree, whch can be done n O(n log n) Can fnd k nearest neghbors n O(k + log n) tme usng a heap 3/26/07 32
3/26/07 33 Reflected Radance Recall the reflected radance equaton Convert ncdent radance nto ncdent flux Reflected radance n terms of ncdent flux Numercally Ω = r r r r d N L f L ω ω ω ω ω ω ) )(, ( ), ( ), ( x x da d N d L ω ω ω ω ) ( ), ( ), ( 2 Φ = x x Ω Φ = r r r r da d f L ), ( ), ( ), ( 2 ω ω ω ω x x = Φ n p p p r p r r r f A L 1 ), ( ), ( 1 ), ( ω ω ω ω x x A = πr 2
How Many Photons? How bg s the dsk radus r? Large enough that the dsk surrounds the n nearest photons. The number of photons used for a radance estmate n s usually between 50 and 500. Radance estmate usng 50 photons A = πr 2 Radance estmate usng 500 photons 3/26/07 34
3/26/07 35 Flterng Too few photons cause blurry results Smple averagng produces a box flterng of photons Photons nearer to the sample should be weghted more heavly Results n a cone flterng of photons = Φ n p p p p r p r p k r r f kr r L 1 2 3 2 ), ( ), ( 1 ) (1 1 ), ( ω ω ω π ω x x x x
Multple Photon Maps Global L(S D)*D photon map Photon stcks to dffuse surface and bounces to next surface (f t survves Russan roulette) Photons don t stck to specular surfaces Caustc LSS*D photon map Hgh resoluton Lght source usually emts photons only n drectons that ht the object creatng the caustc Caustc map photons Global map photons 3/26/07 36
Renderng Rendered by glossy-surface dstrbuted ray tracng When ray hts frst dffuse surface Compute reflected radance of caustc map photons Ignore global map photons Importance sample BRDF f r as usual Use global photon map to mportance sample ncdent radance functon L Evaluate reflectance ntegral by castng rays and accumulatng radances from global photon map Frst dffuse ntersecton. Return radance of caustc map photons here, but gnore global map photons Use global map photons to return radance when evaluatng L at frst dffuse ntersecton. 3/26/07 37
Radosty Radosty: Total rate of energy leavng a surface: Emtted Reflected Model the scene as a set of patches wth constant radosty emtters are patches too Set up lnear system Solve 3/26/07 38
Radosty Equaton Parts: BdA = B : Radosty at da : dfferental area E : emsson rate at ρ : reflectvty at EdA + ρ j B j da F j : form factor Wavelength dependence s mplct Usually just use three (RGB) j F j 3/26/07 39
Form Factors The form factor, F j s the fracton of energy leavng da j that arrves (drectly) at da Form factors consder: Dstance between surfaces Relatve Sze Relatve orentaton Occluson by ntervenng surfaces [Draw Examples] 3/26/07 40
3/26/07 41 Dscretzaton Dscretze the scene nto patches of constant radosty Recprocty relatonshp of form factors [SIEG84]: + = j j j j A B F A E A B d d d ρ + = j j j j A B F E A A B ρ becomes j j j j j j A A F F A F A F = = + = j j j F B E B ρ
3/26/07 42 System of Equatons = j j j F B B E ρ = n n nn n n n n n n n E E E B B B F F F F F F F F F 2 1 2 1 2 1 2 2 22 2 21 2 1 1 12 1 11 1 1 1 1 ρ ρ ρ ρ ρ ρ ρ ρ ρ What can we say about about F? Form factors n any row or column sum to 1 (n a closed envronment)
Solvng The matrx s dagonally domnant and Gauss- Sedel teraton s guaranteed to converge Soluton proceeds one row at a tme usng estmates from prevous rows At each step the radosty of a patch s updated based on other approxmaton of other patches Emtters appear frst 3/26/07 43
Renderng The radostes are constant across the entre patch area Smply renderng the patches produces tled appearance Instead nterpolate radostes to the vertces and use Gourad shadng from Baum et al. [1991] 3/26/07 44
Calculatng Form Factors 1 cosφcosφj Fj = 2 V( x, y)dxdy x P r A y P π j Orgnal Radosty paper [Goral et al. 84] used analytcal approach Expensve Dffcult to ncorporate occluson Common technques: Hemcube Ray castng 3/26/07 45
Form factor between two polygons (actually just a part of t) 3/26/07 46
Hemcube Dspenses wth outer ntegral (assumes lttle varaton over ) Uses fact that projecton of surface onto boundng volume has same form factor as orgnal surface Surround the center of patch wth a pxelated half cube Precompute form factor of each pxel Rasterze the scene onto the faces of the hemcube Form factor approxmated as the sum form factors of each pxel t covers 3/26/07 47
Hemcube Lmtatons Alasng Occluson close to surface Close surfaces (why?) Lght sources (why?) 3/26/07 48
Ray castng Compute pont to patch form factor analytcally Use raytracng to determne vsblty factor Generally, less effcent than hemcube 3/26/07 49