Monte Carlo Renderng Last Tme? Modern Graphcs Hardware Cg Programmng Language Gouraud Shadng vs. Phong Normal Interpolaton Bump, Dsplacement, & Envronment Mappng Cg Examples G P R T F P D Today Does Ray Tracng Smulate Physcs? Monte-Carlo Integraton Samplng Advanced Monte-Carlo Renderng Does Ray Tracng Smulate Physcs? No. tradtonal ray tracng s also called backward ray tracng In realty, photons actually travel from the lght to the eye Forward Ray Tracng Start from the lght source But very, very low probablty to reach the eye What can we do about t? Always send a ray to the eye. stll not effcent Transparent Shadows? What to do f the shadow ray sent to the lght source ntersects a transparent object? Pretend t s opaque? Multply by transparency color? (gnores refracton & does not produce caustcs) Unfortunately, ray tracng s full of drty trcks 1
Is ths Tradtonal Ray Tracng? Refracton and the Lfeguard Problem Runnng s faster than swmmng Water Beach Lfeguard Images by Henrk Wann Jensen No, Refracton and complex reflecton for llumnaton are not handled properly n tradtonal (backward) ray tracng Person n trouble Swm Run What makes a Ranbow? Refracton s wavelength-dependent Refracton ncreases as the wavelength of lght decreases volet and blue experence more bendng than orange and red Usually gnored n graphcs Ranbow s caused by refracton + nternal reflecton + refracton The Renderng Equaton Clean mathematcal framework for lghttransport smulaton At each pont, outgong lght n one drecton s the ntegral of ncomng lght n all drectons multpled by reflectance property Pnk Floyd, The Dark Sde of the Moon From Color and Lght n Nature by Lynch and Lvngstone Today Does Ray Tracng Smulate Physcs? Monte-Carlo Integraton Probabltes and Varance Analyss of Monte-Carlo Integraton Samplng Advanced Monte-Carlo Renderng Monte-Carlo Computaton of π Take a random pont (x,y) n unt square Test f t s nsde the ¼ dsc Is x 2 + y 2 < 1? Probablty of beng nsde dsc? area of ¼ unt crcle / area of unt square = π /4 π 4 * number nsde dsc / total number The error depends on the number or trals 2
Convergence & Error Let s compute 0.5 by flppng a con: 1 flp: 0 or 1 average error = 0.5 2 flps: 0, 0.5, 0.5 or 1 average error = 0. 25 4 flps: 0 (*1),0.25 (*4), 0.5 (*6), 0.75(*4), 1(*1) average error = 0.1875 Unfortunately, doublng the number of samples does not double accuracy Another Example: We know t should be 1.0 In practce wth unform samples: error σ 2 - σ 2 N Revew of (Dscrete) Probablty Random varable can take dscrete values x Probablty p for each x 0 < p < 1, Σ p =1 Expected value Expected value of functon of random varable f(x ) s also a random varable Varance & Standard Devaton Varance σ 2 : devaton from expected value Expected value of square dfference Also Standard devaton σ: square root of varance (noton of error, RMS) Monte Carlo Integraton Turn ntegral nto fnte sum Use n random samples As n ncreases Expected value remans the same Varance decreases by n Standard devaton (error) decreases by Thus, converges wth 1 n 1 n Advantages of MC Integraton Few restrctons on the ntegrand Doesn t need to be contnuous, smooth,... Only need to be able to evaluate at a pont Extends to hgh-dmensonal problems Same convergence Conceptually straghtforward Effcent for solvng at just a few ponts 3
Dsadvantages of MC Integraton Nosy Slow convergence Good mplementaton s hard Debuggng code Debuggng math Choosng approprate technques Punctual technque, no noton of smoothness of functon (e.g., between neghborng pxels) Questons? 1 glossy sample per pxel 256 glossy samples per pxel Today Does Ray Tracng Smulate Physcs? Monte-Carlo Integraton Samplng Stratfed Samplng Importance Samplng Advanced Monte-Carlo Renderng Domans of Integraton Pxel, lens (Eucldean 2D doman) Tme (1D) Hemsphere Work needed to ensure unform probablty Example: Lght Source We can ntegrate over surface or over angle But we must be careful to get probabltes and ntegraton measure rght! Samplng the source unformly source Samplng the hemsphere unformly Stratfed Samplng Wth unform samplng, we can get unlucky E.g. all samples n a corner To prevent t, subdvde doman Ω nto non-overlappng regons Ω Each regon s called a stratum Take one random samples per Ω hemsphere 4
Example Borrowed from Henrk Wann Jensen Glossy Renderng Integrate over hemsphere BRDF tmes cosne tmes ncomng lght I ( Unstratfed Stratfed Slde from Jason Lawrence Samplng a BRDF Samplng a BRDF 5 Samples/Pxel 25 Samples/Pxel U( U( P( P( Slde from Jason Lawrence Slde from Jason Lawrence Samplng a BRDF Importance Samplng 75 Samples/Pxel U( P( Choose p wsely to reduce varance p that resembles f Does not change convergence rate (stll sqrt) But decreases the constant Slde from Jason Lawrence bad unform good 5
Results 1200 Samples/Pxel Today Does Ray Tracng Smulate Physcs? Monte-Carlo Integraton Samplng Advanced Monte-Carlo Renderng Tradtonal mportance functon Better mportance by Lawrence et al. Ray Castng Cast a ray from the eye through each pxel Ray Tracng Cast a ray from the eye through each pxel Trace secondary rays (lght, reflecton, refracton) Monte-Carlo Ray Tracng Importance of Samplng the Lght Cast a ray from the eye through each pxel Cast random rays to accumulate radance contrbuton Recurse to solve the Renderng Equaton Should also systematcally sample the prmary lght 1 path per pxel Wthout explct lght samplng Wth explct lght samplng 4 path per pxel 6
Monte Carlo Path Tracng Trace only one secondary ray per recurson But send many prmary rays per pxel (performs antalasng as well) Ray Tracng vs Path Tracng 2 bounces 5 glossy samples 5 shadow samples How many rays cast per pxel? 1man ray + 5 shadow rays + 5 glossy rays + 5x5 shadow rays + 5*5 glossy rays + 5x5x5 shadow rays = 186 rays How many 3 bounce paths can we trace per pxel for the same cost? 186 rays / 8 ray casts per path = ~23 paths Whch wll probably have less error? Results: 10 paths/pxel Results: 100 paths/pxel Readng for Today Veach & Gubas "Optmally Combnng Samplng Technques for Monte Carlo Renderng" SIGGRAPH 95 Samplng senstve to choce of samples less senstve to choce of samples unform samplng (or unform random) dense samplng where functon has greater magntude To optmally combne samples from dfferent dstrbutons, weght more hghly the samples from the locally densest dstrbuton Naïve samplng strategy Optmal samplng strategy all samples weghted equally weghts (wdth) for dense samples are reduced 7
Optmally combnng samplng technques for Monte Carlo renderng Veach & Gubas, SIGGRAPH 1995 Balance heurstc (8 samples / pxel) Readng for Frday 3/28: "Fast Blateral Flterng for the Dsplay of Hgh-Dynamc Range Images", Durand & Dorsey, SIGGRAPH 2002 Before After The Secret: Chosen unformly wthn the cone of drectons subtended by each lght source (4 samples / pxel) Chosen wth probablty proportonal to the BRDF (4 samples / pxel) Power heurstc (8 samples / pxel) Scene contrast s hgh Dsplay contrast s low Contrast reduced Detals preserved Blateral flter 8