Download presentation
Presentation is loading. Please wait.
Published byDonald Booker Modified over 9 years ago
1
Random-walk solution of the global illumination problem László Szirmay-Kalos
2
Expansion solution of the global illuminaton problem ’’ L(x, ) x LeLe R( 2 ) =1/S p f r ( ,x, )cos ’ f r ( ,y, )cos ’ 2 ’2’2 y M ( n L e ) R( n )L e ( n ) d d n
3
Expansion = n R( n, x)L e ( n, x) d d n dx 1/M i M S( (i) n (i), x (i) ) R( n,x) = w 1 w 2 …w n w i = f r cos ’ L e pixel
4
Why Monte-Carlo expansion? l Avoid the exponential core: –Monte-Carlo or quasi-Monte Carlo integration –Intuitive: R( n,x)· L e ( n,x) integrand= probability · emission l Integrand is –L 2 : MC finite variance –Not of finite variation, but finite length of discontinuities: QMC
5
Importance Sampling: = M n L e = = n R( n )L e ( n ) d d n dp R( n, p) = 1/S p w 1 w 2 …w n, w i =f r cos ’ = M (L e + L e + L e + … ) )) = = M (L e + w 1 L e + w 2 L e + L e … ) d ) d )
6
Iterative importance sampling Pr( i ) w i L e + … ) – reflection prob x (direct lighting + indirect lighting) BRDF sampling: Pr( i ) w i Direct lighting: Pr( i ) L e Global imp. sampling: Pr( i ) w i L in estimate) Adaptive imp. sampling: find a process that converges to Pr( i ) w i L e + … )
7
BRDF sampling: Pr( in | out ) w =f r ( in, out )cos ’ l Transformation of random variables: –1. use spherical coordinates: w( in | out )d =w( , ’)sin ’d d ’ –2. normalization: p( , ’) d d ’ = w d / f r ( in, out )cos ’d scale: a ( out ) = f r ( in, out )cos ’d –3. decomposition: p( , ’) = p ( ) p ’ ( ’) –4. probability distributions: P ’ ( ’)= ’ p ’ ( ) d , P ( )= p ( ) d –5. Generation of uniform random variables r 1, r 2. –6. Find , ’ sample by transforming r 1, r 2 by the inverse probability distributions l ’= P ’ -1 ( r 1 ), = P -1 ( r 2 )
8
Diffuse BRDF sampling Diffuse BRDF sampling 1. use spherical coordinates: w( in | out )d = k d cos ’sin ’d d ’ 2. normalization: albedo= k d p( , ’) = cos ’sin ’/ 3. decomposition: p( , ’) = 1/2 · 2 cos ’sin ’= 1/2 · sin 2 ’ 4. probability distributions: P ( )= /2 , P ’ ( ’)= sin 2 ’ 5. Generation of uniform random variables r 1, r 2. 6. Find , ’ samples = 2 r 2, ’= arcsin r 1
9
Diffuse BRDF class class Diffuse { Color Kd; public: SColor BRDF(Vec& L, Vec& N, Vec& V) { return Kd; } double NextDir(Vec& L, Vec& N, Vec& V) { double theta = asin(sqrt( rand() )); double phi = M_PI * 2.0 * rand(); Vec O = N % Vec(0.0, 0.0, 1.0), P = N % O; // cheat !!! L = N*cos(theta)+O*sin(theta)*cos(phi)+P*sin(theta)*sin(phi); return (cos(theta)/M_PI); } };
10
Diffuse BRDF sampling: geometric approach Diffuse BRDF sampling: geometric approach 1. Generate a uniformly distributed point in a square 2. Reject and generate new if not in the base circle do { x = r 1, y = r 2 } while (x 2 + y 2 > 1) 3. Map to the sphere to find the direction z = 1 - x 2 - y 2 dAdA dA/cos rejected samples dd d cos
11
Specular BRDF sampling 1.use spherical coordinates: w( in | out ) d = k s cos n cos ’ sin d d 2. compromise: p( , ’) k s cos n sin 3. normalization: k s cos n sin d d 2 k s /(n+1) p( , ) = (n+1)/2 cos n sin 3. decomposition: p( , ) = 1/2 · (n+1) cos n sin 4. probability distributions: P ( )= /2 , P ( )= 1- cos n+1 5. Generation of uniform random variables r 1, r 2. 6. Find , ’ samples: = 2 r 2, = arccos r 1 1/(n+1) 7. Radiance is 0 if ’( , degrees
12
Specular BRDF class class Phong { Color Ks; double shine; public: double NextDir(Vec& L, Vec& N, Vec& V) { u = rnd(), v = rnd(); double cos_V_R = pow(u, 1.0/(shine+1) ); double sin_V_R = sqrt(1.0-cos_V_R*cos_V_R ); Vec O = V % Vec(0.0, 0.0, 1.0), P = O % V; Vec R = O*sin_V_R*cos(2.0*M_PI*v) + P*sin_V_R * sin(2.0*M_PI*v) +V*cos_V_R; L = N * (N * R) * 2.0 - R; if (N * L < 0) return 0; return (shine+1)/2/M_PI * pow(cos_V_R, shine); } };
13
Ideal reflection sampling w( in | out ) is non-zero just for the reflection direction l Select the reflection direction with probability 1.
14
Infinite dimensional integrals: Russian roulette 1. MC integral of a bounce: w i L e +...) d i = E[w i L e +...) /p( i )] = E[ L refl ] 2. Compute the reflected radiance with probability s, otherwise assume that it is 0 3. Compensate the error by dividing the radiance by s Expected value is still correct: E[ L refl* ] = s E[ L refl /s ] + (1-s) 0 = E[ L refl ] Variance is increased D 2 [ L refl* ] = s E[ (L refl /s) 2 ] + (1-s) 0 - E 2 [ L refl ]= (1/s - 1) E[(L refl ) 2 ] + D 2 [ L refl ]
15
Selection of the termination probability: albedo BRDF importance sampling: w i L e +...) d i = E[w i ( i, i-1 )/p( i ) L e +...) ] = E[a( i-1 ) L e +...) ] 2. Continuation with the probability of the albedo: if rnd() < a( i-1 ) return L e +... else return 0
16
Russian roulette with QMC Using less number of samples if the integrand is smaller: w L in d ’ Adding an indicator (0/Const) function C( ’, r): w = C( ’, r) dr l Substitution : – w L in d ’ = r ’ C( ’, r) L in d ’ dr
17
Combined BRDF sampling 1.BRDF is a sum of elementary BRDFs: f r = f 1 + f 2 + … + f n, w = w 1 + w 2 + … + w n 2. w L in d = w 1 L in d +... + w n L in d 3. Evaluate this sum randomly: probability of terms: s1, s2, … sn, probability of no term: (1- s1- s2 - …- sn) if term i is selected it is divided by si Expected value: s1 w 1 L in d s1 +... + sn w n L in d sn +(1-..)0= w L in d
18
Low variance estimator l si is the albedo of the BRDF –1. Select reflection model: l probabilities: a1, a2, … an, l stop with (1-a1-a2-…an) –2. Generate the direction using the reflection model –3. L refl L in from the selected direction or 0 if stopped w L in d w1 L in d +...+ wn L in d w1/p1 L in ]+...+ wn/pn L in ] a1 L in ]+...+ an L in ]
19
Combined BRDF class class CombMat : Diffuse, Phong, Reflector, Refractor { enum {NO, DIFF, PHONG, REFLECT, REFRACT} selected; public: double SelectModel(Vec& L, Vec& N, Vec& V); double NextDir(Vec& L, Vec& N, Vec& V, BOOL out); Color BRDF(Vec& L, Vec& N, Vec& V); };
20
SelectModel double CombMat:: SelectModel(Vec& L, Vec& N, Vec& V) { double akd =Diffuse::Albedo(N,V), aks =Phong::Albedo(N,V), akr = Reflector::Albedo(N,V), akt = Refractor::Albedo(N,V); double r = rnd(); if ((r -= akd) < 0) { selected = DIFF; return akd; } if ((r -= aks) < 0) { selected = PHONG; return aks; } if ((r -= akr) < 0) { selected = REFLECT; return akr; } if ((r -= akt) < 0) { selected = REFRACT; return akt; } selected = NO; return 0.0; // Russian roulette }
21
CombMat::Reflect double CombMat::NextDir(Vec& L, Vec& N, Vec& V, BOOL out) { switch (selected) { case DIFFUSE: return Diffuse :: NextDir(L, N, V); case PHONG: return Phong :: NextDir(L, N, V); case REFLECT: return Reflector :: NextDir(L, N, V); case REFRACT: return Refractor :: NextDir(L, N, V, out); }
22
CombMat::BRDF Color CombMat :: BRDF(Vec& L, Vec& N, Vec& V) { switch (selected) { case DIFF: return DiffuseMaterial :: BRDF(L, N, V); case PHONG: return SpecularMaterial :: BRDF(L, N, V); case REFLECT: return (N*L>0): kr() / (N*L): Color(0); case REFRACT: return (-N*L>0): kt() / (-N*L): Color(0); }
23
Requirements of BRDF models l Local illumination and ray-tracing: –Calculation of the L out radiance from L in l Random walk global illumination: –Generation of a random ’ : –Computation of the albedo l diffuse, ideal reflection: yes l Phong, Ward, Schlick, ideal refraction: almost l Cook-Torrance, He-Torrance: no
24
Colored scenes Rendering or potential equation should be solved on wavelengths: 1, 2,…, m –Solving on each wavelength separately: l waste of visibility computation –Solving on all wavelength simultaneosly l scalar importance should be defined on the radiance vector Luminance: e.g.: kd eff = kd i weigth( i )
25
Global importance sampling l Two-pass methods (estimation+random walk) l Preprocessing: photon shooting l Data structure about the radiance (4 5D-table) –5D adaptive tree –photon map –links –wavelets l On the fly importance generation from the data structure
26
Photon shooting + Importance generation 2 4 Photon shooting Looking the photon impact from a patch Dicretising the hemisphere ,, Dicrete pdf 2/6 4/6 ,, 2/6 1 Dicrete CDF Random variable
27
Adaptive importance sampling l Single pass methods l Use previous walks to guide the importance of the future walks –explicit storage of importance: VEGAS sampling: approximate high-D importance functions by the product of 1D functions –implicit: use a process that converges to the desired probability density: Metropolis
28
Metropolis sampling zizi ztzt f(zi)f(zi) z i+1 f(zt)f(zt) acceptance probability: f(z t ) / f(z i ) T Adaptation is guided by a Markov chain
29
Design of a Metropolis l “Arbitrary” mutation function T(z i z t ) l Construct the acceptance a(z i z t ) so that the limiting probabilities: p(z) f(z) z1z1 z2z2 z3z3 p(z 1 ) T(z 1 z 2 ) a(z 1 z 2 ) a(z 1 z 2 ) a(z 2 z 1 ) f (z 2 ) T(z 2 z 1 ) f (z 1 ) T(z 1 z 2 ) = Detailed balance
30
Metropolis algorithm FOR i=1 TO M DO Using z i choose another random, tentative point z t a(z i z t ) = (f (z t ) T(z t z i )) /((f (z i ) T(z i z t )) IF a(z i z t ) > 1 THEN accept z i+1 = z t ELSE // accept with probability a(z i z t ) Generate random number r in [0,1] IF r < a(z i z t ) THEN z i+1 = z t ELSE z i+1 = z i ENDIF ENDFOR
31
Convergence of the probability density z0z0 f(z)f(z) p1p1 p2p2 pp
32
Definition of a Metropolis algorithm l Perturbation (mutation) strategy: –how to find a new tentative sample in the neightborhood of the actual samples. –Req: any state can be reached l Benefits: adaptive, exact importance sampling l Drawbacks: adaptation phase: start-up bias
33
Metropolis method for the rendering equation L e Mutations: perturbing the directions, adding and deleting steps pixel
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.