33
Random-walk solution of Random-walk solution of the global illumination the global illumination problem problem László Szirmay-Kalos

Random-walk solution of the global illumination problem László Szirmay-Kalos

Embed Size (px)

Citation preview

Page 1: Random-walk solution of the global illumination problem László Szirmay-Kalos

Random-walk solution of the Random-walk solution of the global illumination problemglobal illumination problem

László Szirmay-Kalos

Page 2: Random-walk solution of the global illumination problem László Szirmay-Kalos

Expansion solution of the Expansion solution of the global illuminaton problemglobal illuminaton problem

’L(x,)

x

Le

R(2) =1/Sp fr (,x,)cos’fr (,y,)cos’2

’2

y

M ( nLe )R(n)Le(n)

ddn

Page 3: Random-walk solution of the global illumination problem László Szirmay-Kalos

ExpansionExpansion

= nR(n,x)Le(n,x) ddndx

1/M iM S(

(i)n(i),x(i) )

R(n,x) = w1 w2 …wn

wi = fr cos ’

Le

pixel

Page 4: Random-walk solution of the global illumination problem László Szirmay-Kalos

Why Monte-Carlo expansion?Why Monte-Carlo expansion?

Avoid the exponential core:– Monte-Carlo or quasi-Monte Carlo integration

– Intuitive: R(n,x) · Le(n,x) integrand= probability · emission

Integrand is – L2 : MC finite variance

– Not of finite variation, but finite length of discontinuities: QMC

Page 5: Random-walk solution of the global illumination problem László Szirmay-Kalos

Importance Sampling:Importance Sampling:

=M nLe== nR(n)Le(n) ddndp

R(n,p) = 1/Sp w1 w2 …wn, wi =fr cos’

= M (Le + Le + Le + … ) )) = = M (Le+w1Le +w2Le +Le … ) d )

d)

Page 6: Random-walk solution of the global illumination problem László Szirmay-Kalos

Iterative importance samplingIterative importance sampling

Pr(i) wi Le +… )– reflection prob x (direct lighting + indirect lighting)

BRDF sampling: Pr(i) wi

Direct lighting: Pr(i) Le

Global imp. sampling: Pr(i) wi Lin estimate)

Adaptive imp. sampling: find a process that converges to Pr(i) wi Le +… )

Page 7: Random-walk solution of the global illumination problem László Szirmay-Kalos

BRDF sampling: BRDF sampling: Pr(Pr(in in ||outout)) w = w =ffr r ((inin,,outout)cos)cos’’

Transformation of random variables:– 1. use spherical coordinates: w(in |out)d =w(,’)sin’d d’

– 2. normalization: p(,’) d d’ = w d /fr (in,out)cos’d scale: a (out) = fr (in,out)cos’d

– 3. decomposition: p(,’) = p() p’(’)

– 4. probability distributions: P’(’)= ’ p’() d, P()= p () d

– 5. Generation of uniform random variables r1, r2.

– 6. Find ,’ sample by transforming r1, r2 by the inverse probability distributions

’= P’-1(r1), = P

-1(r2)

Page 8: Random-walk solution of the global illumination problem László Szirmay-Kalos

Diffuse BRDF samplingDiffuse BRDF sampling1. use spherical coordinates:

w(in |out)d = kd cos’sin ’d d’2. normalization: albedo= kd

p(,’) = cos’sin ’/3. decomposition:

p(,’) = 1/2 · 2 cos’sin ’= 1/2 · sin 2’ 4. probability distributions:

P()= /2, P’(’)= sin2 ’ 5. Generation of uniform random variables r1, r2.6. Find ,’ samples = 2 r2, ’= arcsin r1

Page 9: Random-walk solution of the global illumination problem László Szirmay-Kalos

Diffuse BRDF classDiffuse 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); }};

Page 10: Random-walk solution of the global illumination problem László Szirmay-Kalos

Diffuse BRDF sampling: Diffuse BRDF sampling: geometric approachgeometric approach

1. Generate a uniformly distributed point in a square2. Reject and generate new if not in the base circle

do { x = r1, y = r2 } while (x2 + y2 > 1)

3. Map to the sphere to find the directionz = 1 - x2

- y2

dA

dA/cos

rejected samples

d

d cos

Page 11: Random-walk solution of the global illumination problem László Szirmay-Kalos

Specular BRDF samplingSpecular BRDF sampling1.use spherical coordinates:

w(in |out) d = ks cosncos’ sind d 2. compromise: p(,’) ks cosnsin3. normalization: kscosnsind d2 ks /(n+1)

p(,) = (n+1)/2 cosnsin3. decomposition: p(,) = 1/2 · (n+1) cosnsin4. probability distributions:

P()= /2, P()= 1- cosn+1 5. Generation of uniform random variables r1, r2.6. Find ,’ samples:

= 2 r2, = arccos r11/(n+1)

7. Radiance is 0 if ’(, degrees

Page 12: Random-walk solution of the global illumination problem László Szirmay-Kalos

Specular BRDF classSpecular BRDF classclass 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); }};

Page 13: Random-walk solution of the global illumination problem László Szirmay-Kalos

Ideal reflection samplingIdeal reflection sampling

w(in |out) is non-zero just for the reflection direction

Select the reflection direction with probability 1.

Page 14: Random-walk solution of the global illumination problem László Szirmay-Kalos

Infinite dimensional integrals: Infinite dimensional integrals: Russian rouletteRussian roulette

1. MC integral of a bounce: wiLe +...) di = E[wiLe +...) /p(i)] = E[ Lrefl ]

2. Compute the reflected radiance with probability s, otherwise assume that it is 03. Compensate the error by dividing the radiance by s

Expected value is still correct: E[ Lrefl* ] = s E[ Lrefl/s ] + (1-s) 0 = E[ Lrefl ]Variance is increased D2[ Lrefl* ] = s E[ (Lrefl/s)2 ] + (1-s) 0 - E2[ Lrefl ]= (1/s - 1) E[(Lrefl)2 ] + D2[ Lrefl ]

Page 15: Random-walk solution of the global illumination problem László Szirmay-Kalos

Selection of the termination Selection of the termination probability: albedoprobability: albedo

BRDFimportance sampling:wiLe +...) di = E[wi (i, i-1)/p(i) Le +...) ] = E[a(i-1) Le +...) ]

2. Continuation with the probability of the albedo:if rnd() < a(i-1) return Le +...

else return 0

Page 16: Random-walk solution of the global illumination problem László Szirmay-Kalos

Russian roulette with QMCRussian roulette with QMC

Using less number of samples if the integrand is smaller: w Lin d’

Adding an indicator (0/Const) function

C(’,r): w = C(’,r) dr Substitution :

– w Lin d’ = r’C(’, r) Lin d’ dr

Page 17: Random-walk solution of the global illumination problem László Szirmay-Kalos

Combined BRDF samplingCombined BRDF sampling1.BRDF is a sum of elementary BRDFs:

fr = f1 + f2 + … + fn, w = w1 + w2 + … + wn

2. wLin d = w1Lin d + ... + wnLin 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 w1Lin ds1 + ... + sn wnLin dsn +(1-..)0=wLin d

Page 18: Random-walk solution of the global illumination problem László Szirmay-Kalos

Low variance estimatorLow variance estimator si is the albedo of the BRDF

– 1. Select reflection model: probabilities: a1, a2, … an, stop with (1-a1-a2-…an)

– 2. Generate the direction using the reflection model

– 3. Lrefl Lin from the selected direction or 0 if stopped wLin dw1Lin d+...+wnLin d w1/p1Lin ]+...+ wn/pnLin ]a1Lin ]+...+ anLin ]

Page 19: Random-walk solution of the global illumination problem László Szirmay-Kalos

Combined BRDF classCombined 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);};

Page 20: Random-walk solution of the global illumination problem László Szirmay-Kalos

SelectModelSelectModeldouble 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}

Page 21: Random-walk solution of the global illumination problem László Szirmay-Kalos

CombMat::ReflectCombMat::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); }}

Page 22: Random-walk solution of the global illumination problem László Szirmay-Kalos

CombMat::BRDFCombMat::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); }}

Page 23: Random-walk solution of the global illumination problem László Szirmay-Kalos

Requirements of BRDF modelsRequirements of BRDF models

Local illumination and ray-tracing:– Calculation of the Lout radiance from Lin

Random walk global illumination:– Generation of a random ’ :– Computation of the albedo

diffuse, ideal reflection: yes Phong, Ward, Schlick, ideal refraction: almost Cook-Torrance, He-Torrance: no

Page 24: Random-walk solution of the global illumination problem László Szirmay-Kalos

Colored scenesColored scenes

Rendering or potential equation should be solved on wavelengths: 1,2 ,…, m

– Solving on each wavelength separately: waste of visibility computation

– Solving on all wavelength simultaneosly scalar importance should be defined on the

radiance vector Luminance: e.g.: kdeff = kdiweigth(i)

Page 25: Random-walk solution of the global illumination problem László Szirmay-Kalos

Global importance samplingGlobal importance sampling

Two-pass methods (estimation+random walk) Preprocessing: photon shooting Data structure about the radiance (4 5D-table)

– 5D adaptive tree– photon map– links– wavelets

On the fly importance generation from the data structure

Page 26: Random-walk solution of the global illumination problem László Szirmay-Kalos

Photon shooting + Importance generationPhoton shooting + Importance generation

24

Photon shootingLooking the photonimpact from a patch

Dicretising the

hemisphere

,Dicrete pdf

2/6

4/6

,2/6

1

Dicrete CDF

Randomvariable

Page 27: Random-walk solution of the global illumination problem László Szirmay-Kalos

Adaptive importance samplingAdaptive importance sampling

Single pass methods 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

Page 28: Random-walk solution of the global illumination problem László Szirmay-Kalos

Metropolis samplingMetropolis sampling

zi zt

f(zi)

zi+1

f(zt)

acceptance probability:

f(zt) / f(zi)

T

Adaptation is guided by a Markov chain

Page 29: Random-walk solution of the global illumination problem László Szirmay-Kalos

Design of a MetropolisDesign of a Metropolis

“Arbitrary” mutation function T(zizt )

Construct the acceptance a(zizt ) so that the limiting probabilities: p(z) f(z)

z1

z2

z3

p(z1) T(z1z2 ) a(z1z2 )

a(z1z2 )

a(z2z1 )

f(z2) T(z2z1)

f(z1) T(z1z2 )=

Detailed balance

Page 30: Random-walk solution of the global illumination problem László Szirmay-Kalos

Metropolis algorithmMetropolis algorithmFOR i=1 TO M DO Using zi choose another random, tentative point zt a(zi zt) = (f (zt) T(zt zi)) /((f (zi) T(zi zt)) IF a(zi zt) > 1 THEN accept zi+1 = zt ELSE // accept with probability a(zi zt) Generate random number r in [0,1] IF r < a(zi zt) THEN zi+1 = zt ELSE zi+1 = zi

ENDIFENDFOR

Page 31: Random-walk solution of the global illumination problem László Szirmay-Kalos

Convergence of the Convergence of the probability densityprobability density

z0

f(z)p1

p2

p

Page 32: Random-walk solution of the global illumination problem László Szirmay-Kalos

Definition of a Metropolis Definition of a Metropolis algorithmalgorithm

Perturbation (mutation) strategy:

– how to find a new tentative sample in the neightborhood of the actual samples.

– Req: any state can be reached Benefits: adaptive, exact importance

sampling Drawbacks: adaptation phase: start-up bias

Page 33: Random-walk solution of the global illumination problem László Szirmay-Kalos

Metropolis method for the Metropolis method for the rendering equationrendering equation

Le

Mutations: perturbing the directions, adding and deleting steps

pixel