Computer graphics III – and its solution

Jaroslav Křivánek, MFF UK [email protected]

Global illumination – GI

Direct illumination

2 Review: Reflection equation

 “Sum” (integral) of contributions over the hemisphere:

ω = ω ⋅ ω → ω ⋅ θ ω Lr (x, o ) ∫ Li (x, i ) fr (x, i o ) cos i d i H (x)

n ω Li(x, i) Emitted radiance

Lo(x, ωo) dωi θ L (x,ω ) = L (x,ω ) θo i o o e o + Lr (x,ωo )

Lr(x, ωo) Total outgoing rad. Reflected rad. From local reflection to global light transport

 Reflection equation (local reflection)

L (x,ω ) = L (x,ω ) + L (x,ω )⋅ f (x,ω → ω )⋅cosθ dω o o e o ∫ i i r i o i i H (x)

 Where does the incoming radiance Li(x, ωi) come from?  From other places in the scene !

Lo( r(x, ωi), -ωi) r(x, ωi) ω = ω −ω = Li (x, i ) Lo (r(x, i ), i ) L (x,ω ) i i x Ray casting function

CG III (NPGR010) - J. Křivánek 2015

From local reflection to global light transport

 Plug for Li into the reflection equation

Lo (x, ωo ) = Le (x,ωo ) + ω −ω ⋅ ω → ω ⋅ θ ω ∫ Lo (r(x, i ), i ) fr (x, i o ) cos i d i H (x)

 Incoming radiance Li drops out

 Outgoing radiance Lo at x described in terms of Lo at other points in the scene

CG III (NPGR010) - J. Křivánek 2015 Rendering equation

 Remove the subscript “o” from the outgoing radiance:

ω = ω L (x, o ) Le (x, o ) + ω −ω ω → ω θ ω ∫ L(r(x, i ), i ) fr (x, i o )cos i d i H (x)

 Description of the steady state = energy balance in the scene

 Rendering = calculate L(x, ωo) for all points visible through pixels, such that it fulfils the rendering equation

CG III (NPGR010) - J. Křivánek 2015 Reflection equation vs. Rendering equation Similar form – different meaning

ω = ω + ω ⋅ ω → ω ⋅ θ ω Lo (x, o ) Le (x, o ) ∫ Li (x, i ) fr (x, i o ) cos i d i H (x)  Reflection equation  Describes local light reflection at a single point  Integral that can be used to calculate the outgoing radiance if we know the incoming radiance

L(x,ωo ) = Le (x,ωo ) + L(r(x, ωi ), −ωi )⋅ fr (x, ωi → ωo )⋅cosθi dωi ∫H (x)  Rendering equation  Condition on the global distribution of light in scene  Integral equation – unknown quantity L on both sides Rendering Equation – Kajiya 1986

CG III (NPGR010) - J. Křivánek 2015 sketch

Recursive unwinding of the RE

 Angular form of the RE ω = ω + ω −ω ⋅ ω → ω ⋅ θ ω L(x, o ) Le (x, o ) ∫ L(r(x, '), ') fr (x, ' o ) cos ' d ' H (x)

 To calculate L(x, ωo), we need to calculate L(r(x, ω’), −ω’) for all directions ω’ around the point x  For the calculation of each L(r(x, ω’), −ω’), we need to do the same thing recursively,  etc. r( r(x,ω’), ω’) ω’’ r(x, ω’) ω’ ωo

x CG III (NPGR010) - J. Křivánek 2015 Path tracing, v. zero (recursive form)

getLi (x, ω): y = traceRay(x, ω) return Le(y, –ω) + // emitted radiance Lr (y, –ω) // reflected radiance

Lr(x, ω): ω′ = genUniformHemisphereRandomDir( n(x) ) return 2π * brdf(x, ω, ω′) * dot(n(x), ω′) * getLi(x, ω′)

CG III (NPGR010) - J. Křivánek 2015 Back to the theory: Angular and area form of the rendering equation Angular vs. area form of the RE

 Angular form  integral over the hemisphere in incoming directions

L(x,ωo ) = Le (x,ωo )

+ L(r(x, ω ), −ω )⋅ f (x, ω → ω )⋅cosθ dω ∫ i i r i o i i H (x)

 Substitution cosθ dω = dA r 2

CG III (NPGR010) - J. Křivánek 2015 Angular vs. area form of the RE

 Area form  Integral over the scene surface

L (x,ωo ) = Le (x,ωo )

+ → ⋅ → → ω ⋅ ↔ ⋅ ↔ ∫ L(y x) fr (y x o ) G(x y) V (x y) dAy M scene surface visibility geometry term 1 … y visible from x 0 … otherwise cosθx ⋅cosθy G(x ↔ y) = 2 x − y

CG III (NPGR010) - J. Křivánek 2015 Angular form

 Add radiance contributions to a point from all directions

 For each direction, find the nearest surface

 Implementation in stochastic path tracing:  For a given x, generate random direction(s), for each find the nearest intersection, return the outgoing radiance at that intersection and multiply it with the cosine-weighted BRDF. Average the result of this calculation over all the generated directions over the hemisphere.

CG III (NPGR010) - J. Křivánek 2015 Area form

 Sum up contributions to a point from all other points on the scene surface

 Contribution added only if the two points are mutually visible

 Implementation in stochastic path tracing:  Generate randomly point y on scene geometry. Test visibility between x and y. If mutually visible, add the outgoing radiance at y modulated by the geometry factor.

 Typical use: direct illumination calculation for area light sources CG III (NPGR010) - J. Křivánek 2015

Most rendering algorithms = (approximate) solution of the RE

 Local illumination (OpenGL)  Only point sources, integral becomes a sum  Does not calculate equilibrium radiance, is not really a solution of the RE

 Finite element methods (radiosity) [Goral, ’84]  Discretize scene surface (finite elements)  Disregard directionality of reflections: everything is assumed to be diffuse  Cannot reproduce glossy reflections

CG III (NPGR010) - J. Křivánek 2015 Most rendering algorithms = (approximate) solution of the RE

[Whitted, ’80]  Direct illumination on diffuse and glossy surfaces due to point sources  Indirect illumination only on ideal mirror reflection / refractions  Cannot calculate indirect illumination on diffuse and glossy scenes, soft shadows etc. …

[Cook, ’84]  Estimate the local reflection using the MC method  Can calculate soft shadows, glossy reflections, camera defocus blur, etc.

CG III (NPGR010) - J. Křivánek 2015

Most rendering algorithms = (approximate) solution of the RE

 Path tracing [Kajiya, ’86]  True solution of the RE via the Monte Carlo method  Tracing of random paths (random walks) from the camera  Can calculate indirect illumination of higher order

CG III (NPGR010) - J. Křivánek 2015 From the rendering equation to finite element radiosity

From the rendering equation to radiosity

 Start from the area form of the RE:

L(x, ω ) = L (x, ω ) + o e o

L(y → x)⋅ fr (y → x → ωo )⋅G(x ↔ y)⋅V (x ↔ y) dA ∫M y

 The Radiosity method– assumptions

 Only diffuse surfaces (BRDF constant in ωi and ωo)  Radiosity (i.e. radiant exitance) is spatially constant (flat) over the individual elements

CG III (NPGR010) - J. Křivánek 2015 From the rendering equation to radiosity

 Diffuse surfaces only

 The BRDF is constant in ωi and ωo

ρ(x) ω = ω + → ⋅ ↔ ⋅ ↔ L(x, o ) Le (x, o ) ∫ L(y x) G(x y) V (x y) dAy π M

 Outgoing radiance is independent of ωo and it is equal to radiosity B divided by π G(x ↔ y)⋅V (x ↔ y) = + ρ ⋅ ⋅ B(x) Be (x) (x) ∫ B(y) dAy M π G'(x ↔ y) CG III (NPGR010) - J. Křivánek 2015 From the rendering equation to radiosity

 Spatially constant (flat) radiosity B of the contributing surface elements

N   B(x) = B (x) + ρ(x)⋅ B ⋅ G'(x ↔ y) dA  e ∑ j  ∫ y, j  j=1  Aj 

Radiosity of the j-th element

Geometry factor between surface element j and point x

CG III (NPGR010) - J. Křivánek 2015 From the rendering equation to radiosity

 Spatially constant (flat) radiosity of the receiving surface element i:  Average radiosity over the element 1 B = B(x) dA = i A ∫ i i Ai

θ j dAj N   Aj  1  = Be,i + ρi ⋅ B j ⋅ G'(x ↔ y) dAy, j dAx,i θ ∑  ∫ ∫  i j=1 A i Ai Aj   dAi Ai

Fij … form factor

CG III (NPGR010) - J. Křivánek 2015 Classic radiosity equation

 System of linear equations

N Bi = Be,i + ρi ⋅∑ B j ⋅ Fij j=1  Form factors 1 = ↔ Fij ∫ ∫G'(x y) dAy, j dAx,i Ai A A i j  Conclusion: the radiosity method is nothing but a way to solve the RE under a specific set of assumptions

CG III (NPGR010) - J. Křivánek 2015 Radiosity method

 Classical radiosity 1. Form facto calculation (Monte Carlo, hemicube, …) 2. Solve the linear system (Gathering, Shooting, …)

 Stochastic radiosity  Avoids explicit calculation of form factors  Metoda Monte Carlo

 Radiosity is not practical, not used  Scene subdivision -> sensitive to the quality of the geometry model (but in reality, models are always broken)  High memory consumption, complex implementation CG III (NPGR010) - J. Křivánek 2015 The operator form of the RE RE is a Fredhom integral equation of the 2nd kind

General form the Fredholm integral equation of the 2nd kind

= + ′ ′′ fx() gx ()∫ kxxfxdx (, )( )

unknown known equation function functions “kernel”

Rendering equation:

ω = ω + ω −ω ⋅ ω → ω ⋅ θ ω L(x, o ) Le (x, o ) ∫ L(r(x, i ), i ) fr (x, i o ) cos i d i H (x)

CG III (NPGR010) - J. Křivánek 2015 Linear operators

 Linear operators act on functions  (as matrices act on vectors) hx()= ( L f )() x

 The operator is linear if the “acting” is a linear operation L( af+= bg )( a L  f )( + b L g )

 Examples of linear operators (K f )( x )≡ ∫ k ( x , x′ ) f ( x ′′ ) dx ∂f (Dfx )()≡ () x ∂x

CG III (NPGR010) - J. Křivánek 2015 Transport operator

(T  L)(x, ωo ) ≡ L(x, ωi )⋅ fr (x, ωi → ωo )⋅cosθi dωi ∫H (x)

 Rendering equation

L = Le +T  L

CG III (NPGR010) - J. Křivánek 2015 Solution of the RE in the operator form

 Rendering equation

L = Le +T  L

 Formal solution

(I −T )  L = L e −1 L = (I −T )  Le

 unusable in practice – the inverse cannot be explicitly calculated

CG III (NPGR010) - J. Křivánek 2015 Expansion of the rendering equation

 Recursive substitution L

L = Le +TL

= Le +T (Le +TL) 2 = Le +TLe +T L

 n-fold repetition yields the Neumann series

n i n+1 L = ∑T Le +T L i=0

CG III (NPGR010) - J. Křivánek 2015 Expansion of the rendering equation

 If T is a contraction (tj. ||T|| < 1, which holds for the RE), then limT n+1L = 0 n→∞

 Solution of the rendering equation is then given by ∞ = i L ∑T Le i=0

CG III (NPGR010) - J. Křivánek 2015 A different derivation of the Neumann series

 Formal solution of the rendering equation

L = (I −T )−1  L e  Proposition (I −T )−1 = I +T +T 2 +...  Proof

−  − −1 = −  + + 2 + (I T ) (I T ) (I T ) (I T T ...) = (I +T +T 2 +...) − (T +T 2 +T 3 +...) = I

CG III (NPGR010) - J. Křivánek 2015 Rendering equation

L = Le + T  L

L = Le + T  L

 Solution: Neumann series 2 3 L = Le + TLe + T Le + T Le +...

CG III (NPGR010) - J. Křivánek 2015 Progressive approximation

Le T  Le T T  Le T T T  Le

+  2 3 Le Le T Le Le +TLe +T Le Le +...+T Le

CG III (NPGR010) - J. Křivánek 2015 Progressive approximation

 Each application of T corresponds to one step of reflection & light propagation

2 3 L = Le +TLe +T Le +T Le +...

emission one-bounce indirect illumination

direct two-bounce illumination indirect illumination OpenGL shading CG III (NPGR010) - J. Křivánek 2015 Contractivity of T

 Holds for all physically correct models  Follows from the conservation of energy

 It means that repetitive application of the operator lower the remaining light energy (makes sense, since reflection/refraction cannot create energy)

 Scenes with white or highly specular surfaces  reflectivity close to 1  to achieve convergence, we need to simulate more bounces of light

CG III (NPGR010) - J. Křivánek 2015 Alright, so what have we achieved?

Rendering Solution through the equation Neumann series ∞ i L = Le +T  L L = ∑T Le i=0  We have replaced an integral equation by a sum of simple integrals  Great we know how to calculate integrals numerically (the Monte Carlo method), which means that we know how to solve the RE, and that means that we can render images, yay!  Recursive application to T corresponds to the recursive ray tracing from the camera

CG III (NPGR010) - J. Křivánek 2015 What exact integral are we evaluating, then?

L(x, ωo ) = Le (x, ωo ) +

Le (y → x)⋅ fr (y → x → ωo )⋅G(x ↔ y)⋅V (x ↔ y) dA + ∫M y

Le (z → y)⋅[ fr (z → y → x)⋅G(y ↔ z)⋅V (y ↔ z)]⋅ ∫∫M

⋅[ fr (y → x → ωo )⋅G(x ↔ y)⋅V (x ↔ y)]dAydAz +

Le (ž → z) ... dA dA dA ∫∫∫M y z ž

CG III (NPGR010) - J. Křivánek 2015 Paths vs. recursion: Same thing, depends on how we look at it

 Paths in a high-dimensional path space 2 3 L = Le +TLe +T Le +T Le +...

 Recursive solution of a series of nested (hemi)spherical integrals:

L = Le +T (Le +T (Le +T (Le +...

CG III (NPGR010) - J. Křivánek 2015 Recursive interpretation We’ve seen this already, right? But unlike at the beginning of the lecture, by now we know this  Angular form of the RE actually solves the RE. ω = ω + ω −ω ⋅ ω → ω ⋅ θ ω L(x, o ) Le (x, o ) ∫ L(r(x, '), ') fr (x, ' o ) cos ' d ' H (x)

 To calculate L(x, ωo) I need to calculate L(r(x, ω’), −ω’) for all directions ω’ around the point x.  For the calculation of each L(r(x, ω’), −ω’) I need to do the same thing recursively  etc. r( r(x,ω’), ω’) ω’’ r(x, ω’) ω’ ωo

x CG III (NPGR010) - J. Křivánek 2015 Path tracing, v. zero (recursive form)

getLi (x, ω): y = traceRay(x, ω) return Le(y, –ω) + // emitted radiance Lr (y, –ω) // reflected radiance

Lr(x, ω): ω′ = genUniformHemisphereRandomDir( n(x) ) return 2π * brdf(x, ω, ω′) * dot(n(x), ω′) * getLi(x, ω′)

CG III (NPGR010) - J. Křivánek 2015 Path tracing, v. 2012, Renderer

© 2012 Columbia Pictures Industries, Inc. All Rights Reserved. CG III (NPGR010) - J. Křivánek 2015

Path tracing [Kajiya86]

 Only one secondary ray at each intersection  Random selection of interaction (diffuse reflection, refraction, etc., …)  Direct illumination: two strategies  Hope that the generated secondary ray hits the light source, or  Explicitly pick a point on the light source  Trace hundreds of paths through each pixel and average the result  Advantage over distributed ray tracing: now branching of the ray tree means no explosion of the number of rays with recursion depth CG III (NPGR010) - J. Křivánek 2015