CS174b Computer graphics Radiosity Handout Radiosity

Overview

In order to create realistic images, one must understand the properties of light and the human visual system. This handout attempts to characterize the prop- erties of light and visual perception in order to provide a ﬁrm basis for the development of image synthesis algortihms.

Radiometry is the study of the physical measurement of electromagnetic energy. Since light is simply one form of electromagnetic energy, the ﬁeld of radiometry oﬀers many theories and algorithms regarding the properties of light.

1.1 Radiance One of the most fundamental quantities that radiometry brings to image syn- thesis is radiance. Radiance is the power per unit projected area perpendicular to the ray, per unit solid angle in the direction of the ray and is denoted L(x, ω).

We note that radiance is a function of ﬁve independant variables, three specify position and two specify direction. Radiance is extremely useful in image syn- thesis in that all other radiometric quantities can be calculated from it. We can now deﬁne the diﬀerential ﬂux contained within a small beam as:

dΦ= L(x, ω) cosθ dω dA (1.1)

Where θ is the angle between the surface normal and the beam direction, dω is the diﬀerential solid angle of the beam, and dA is the diﬀerential cross-sectional area of the beam.

It is important to note that the radiance in the direction of a ray is constant along the ray. This can be shown by considering the total ﬂux contained within a diﬀerential pencil of light (see Figure 1):

dΦ= L1 dω1 dA1 = L2 dω2 dA2 (1.2)

1 Figure 1: Invariance of radiance within a pencil of light

2 2 but since dω1 = dA2/r and dω2 = dA1/r , we can deﬁne: dA dA T = dω dA = dω dA = 1 2 (1.3) 1 1 2 2 r2 T is the throughput of the beam. Note that the throughput is purely a function of the geometry of the beam, therefore it directly follows that:

L1 = L2 (1.4)

1.2 Irradiance Another important quantity related to radiance is irradiance. Irradiance, E, is the radiant energy per unit area incident on a surface.

E = Li cosθ dω (1.5) Z Ω

We can deﬁne the term cosθ dω to be the projected solid angle. This quantity can be thought of as the projection of the diﬀerential area on the surface of a sphere onto the base of the sphere (see ﬁgure Figure 2). One can note that the integral of this projected solid angle is simply the area of the base of the unit hemisphere, π.

1.3 Radiosity Radiosity, B, is similiar to irradiance. However, instead of computing the energy incident on a surface, radiosity is the energy per unit area exiting a surface.

2 Figure 2: Projected Solid Angle

B = Lo cosθ dω (1.6) Z Ω

1.4 Radiant Intensity While the above quatities are extremely useful in categorizing the transport of light between surfaces, they all prove to be inadequate in describing the energy distribution of point light sources. We can easily overcome this problem by simply deﬁning a new radiometric quantity, radiant intensity. The ﬂux in a small beam of of diﬀerential solid angle dω is given by:

dΦ ≡ I(ω)dω (1.7)

3 Where I is the radiant intensity of the light source (power per solid angle)

The total ﬂux of the light source is given by:

Φ= I(ω)dω (1.8) Z Ω

For an isotropic point light we can see that:

Φ I = (1.9) 4π One can now determine the irradiance on a diﬀerential surface caused by a point light source by determining the solid angle of the diﬀerential area from the view of the light source. This gives:

dω Φ cosθ E = I = 2 (1.10) dA 4π |x − xs|

Where x denotes the position of the surface element and xs denotes the position of the light source. From this equation, one can easily see the 1/r2 fall-oﬀ of the inverse square law.

2 Rendering Equations

One may now ask, given these radiometric quantities, how does one categorize the distribution of light in a given envionment? In the following sections, we will derive the rendering equation, a uniﬁed equation of light transport for a given environment as well as a simpliﬁed version of this equation known as the radiosity equation. We begin by examining how to mathematically categorize the reﬂection of light from surfaces.

2.1 Bidirectional Reﬂectance Distribution Functions Given a certain amount of light incident on a surface, we wish to calculate the amount of light reﬂected in a given direction. The amount of light reﬂected in a direction ωr is proportional to the incident irradiance from the direction ωi. More succintly:

dLr(ωr) ∝ dE(ωi) (2.1)

4 The exact amount that this incident irradiance is scaled by is called the bidi- rectional reﬂection distribution function (BRDF). The BRDF if the ratio of reﬂected radiance in the direction ωr to the diﬀerential irradiance in the direc- tion ωi that creates it.

Lr(ωr) fr(ωi → ωr) ≡ (2.2) Li cosθ dωi If the BRDF is physically-based, then the incident and reﬂected directions are interchangeable.

fr(ωi → ωr)= fr(ωr → ωi) (2.3) One can also note that the BRDF is a high dimensional function (4 dimensional for the two directions and another 3 if the BRDF varies with position). However, if the BRDF is isotropic (rotating the surface about its normal does not change the BRDF), the dimensionality of the BRDF can be reduced. An isotropic surface implies:

fr((θi, φi + φ) → (θr, φr + φ)) = fr((θi, φi) → (θr, φr)) (2.4) From this, one can see that an isotropic BRDF has only three degrees of freedom for direction (and possibly three for position).

One can see that adding light from one incident direction has no eﬀect on the amount reﬂected from other incident directions. The linearity of reﬂection allows one to express the total amount of light reﬂected by a surface in a given direction by the hemispherical integration over all possible incident directions. This is known as the reﬂectance equation:

Lr(ωr)= fr(ωi → ωr)Li(ωi) cosθ dωi (2.5) Z Ωi

2.1.1 Mirror Reﬂection We now derive the BRDFs for two common reﬂection models, mirror reﬂection and pure Lambertian diﬀuse reﬂection. For a perfect mirror, all of the incoming irradiance is reﬂected along the mirror direction:

θr = θi

φr = φi ± π

Lr(θr, φr) = Li(θi, φr ± π)

5 One can express this with the following BRDF:

δ(θr − θi) fr,mirror = δ(φr − (φi ± π)) (2.6) cosθi The above function shows that, even for relatively simple reﬂection models, the BRDF can be inﬁnite. Many times, it is easier to use a quantity ranging from 0 to 1, representing the percent of reﬂection. This leads to the notion of reﬂectance. Reﬂectance is deﬁned as the ratio of reﬂected ﬂux to incident ﬂux:

Lr(ωr) cosθr dωr Z dΦ Ωr r = (2.7) dΦi Li(ωi) cosθi dωi Z Ωi

fr(ωi → ωr)Li(ωi) cosθi cosθr dωi dωr Z Z Ωr Ωi = (2.8) Li(ωi) cosθi dωi Z Ωi While the reﬂectance now is bounded from 0 to 1, it also now depends on the incoming radiance distribution, Li. This restriction can be removed if Li is assumed to be constant (uniform and isotropic). It can then be removed from the integrals yielding a relationship between reﬂectance and the BRDF:

fr(ωi → ωr) cosθi dωi dωr Z Z Ωr Ωi = (2.9) cosθi dωi Z Ωi

2.1.2 Lambertian Diﬀuse Reﬂection In the diﬀuse reﬂection model, light is assumed to be scattered equally in all directions (independent of incident direction). This means that the BRDF is constant, giving:

Lr,diffuse = fr,diffuse Li(ωi) cosθi dωi Z Ωi

6 = fr,diffuse Li(ωi) cosθi dωi Z Ωi

= fr,diffuse E (2.10)

The above equation shows that the reﬂected radiance is constant (the same in all directions). This immediately leads to a simpliﬁed equation for the radiosity:

B = π Lr,diffuse (2.11)

Since the reﬂected radiance is constant, one can show that the reﬂectivity is also constant:

Lr(ωr) cosθr dωr Z Ωr ρdiffuse = Li(ωi) cosθi dωi Z Ωi

Lr,diffuse cosθr dωr Z Ωr = E π L = r,diffuse E

= π fr,diffuse (2.12)

And the reﬂectance is related to the radiosity by:

B ρ = (2.13) diffuse E 2.2 The Rendering Equation The last concept needed for the development of a comprehensive rendering equa- tion is the ability to compute the incident radiance distribution at a point, or the illumination model. Local illumination models examine only the current surface and light sources, while global models consider the entire environment to compute the incident radiance. We will begin with a look at local models, followed by a derivation of global models and conclude by incorporating these into the unifying rendering equation.

7 2.2.1 Local Illumination Local illumination models depend solely on the properties of the light sources and the surface to be shaded. For this reason, local models cannot be used to determine many lighting features such as shadows, reﬂections, and color bleeding. Since local models have no concept of the surrounding environment, it is assumed that all of the light reaches the surface. In order to derive the local model for point light sources, we restate the reﬂectance equation and the irradiance from a point light source:

Lr(ωr) = fr(ωi → ωr)Li(ωi) cosθ dωi (2.14) Z Ωi Φ cosθ E = 2 (2.15) 4π |x − xs|

The radiance from the point light source can then be expressed as

Φ 1 Li(ωi) = 2 δ(θi − θs)δ(φi − φs) (2.16) 4π |x − xs|

Where (θs, φs) deﬁnes the direction to the light source. Substituting this into the reﬂectance equation yields

Φ cosθ Lr(ωr)= 2 fr(ωr,ωs) (2.17) 4π |x − xs|

This is the model used by most 3D graphics hardware. These equations can be extended to handle light sources with arbitrary distributions, directional lights, and even area lights. However, local models cannot deal with global phenomena in the environment such as inter-reﬂection and shadowing. These issues are dealt with through global illumination models.

2.2.2 Global Illumination Since global illumination models deal directly with the interaction of diﬀerent surfaces in the environment, one must ﬁrst derive how the radiance reﬂected from one surface aﬀects the radiance at another surface. Since radiance is in- variant along a ray, the incident radiance at a point x′ caused by radiance from another point x is

′ ′ Li(x ,ωi)= Lo(x, ωo) V (x, x ) (2.18)

8 ′ Where ωi is the direction vector from x to x and ωo is the opposite direction vector (from x to x′). V (x, x′) represents the visibility of the points x and x′. It has the value 1 if both x and x′ are mutally visible and 0 otherwise. There- fore, the incoming radiance from a point x′ along a ray is simply the outgoing radiance from the visible point x along that ray.

Looking back at the reﬂectance equation, we see that we have an equation involving the spherical integral around a point. However, we wish to understand how each surface aﬀects the radiance of the other surfaces. We must convert this spherical integral to an integral over all surfaces. This can be done by relating the solid angle subtended by a surface to its surface area

cosθo dA dωi = 2 (2.19) |x − x′| Forming the projected solid angle then yields

cosθi cosθo ′ dωi cosθi dA = 2 dA = G(x, x ) dA (2.20) |x − x′| The term G(x, x′) is called the geometry term in that it only depends on the geometry of the scene (not the distribution of light). G(x, x′) is deﬁned as

′ ′ cosθi cosθo G(x, x )= G(x , x)= 2 (2.21) |x − x′| Using the above equations, we can now write the reﬂectance equation as

′ ′ ′ ′ ′ ′ L(x ,ω )= fr(−ω, x ,ω ) L(x, ω) G(x, x ) V (x, x )dA (2.22) Z S

This equation expresses the outgoing radiance from a point x′ in the direction ω′ by the contributions from all other surface points x weighted by the BRDF, the geometry function and the visibility function. The equation can be repara- materized as follows

′ ′′ ′ ′′ ′ ′ ′ L(x → x )= fr(x → x → x ) L(x → x ) G(x, x ) V (x, x )dA (2.23) Z S

Here, the directions have been implicitly deﬁned by source and destination points. This equation has a fairly simple physical interpretation: The radi- ance sent from x′ to x′′ is simply the amount of radiance sent from all other

9 visible points x in the scene to the point x′ and then reﬂected to the point x′′.

The only other source of radiance that must be added to this equation to derive the complete rendering equation is the amount of radiance directly emitted from x′ to x′′. Adding this term yields the rendering equation introduced by Kajiya [Kaj86]

′ ′′ ′ ′′ L(x → x )= Le(x → x )

′ ′′ ′ ′ ′ + fr(x → x → x )L(x → x )G(x, x )V (x, x )dA (2.24) Z S

2.3 The Radiosity Equation Under the assumption that all surfaces are Lambertian diﬀuse reﬂectors, the rendering equation can be simpliﬁed greatly. This is the radiosity assumption which leads to the following radiosity equation:

′ ′′ ′ ′′ ′ ′′ ′ ′ ′ L(x → x ) = Le(x → x )+ fr(x → x → x )L(x → x ) G(x, x ) V (x, x ) dA Z S

′ ′′ ′ ′′ ′ ′ ′ ′ L(x → x ) = Le(x → x )+ fr(x ) L(x → x ) G(x, x ) V (x, x ) dA Z S ′ ′ ′′ ′ ′′ ρ(x ) ′ ′ ′ L(x → x ) = Le(x → x )+ L(x → x ) G(x, x ) V (x, x ) dA π Z S B(x′) E(x′) ρ(x′) B(x) = + G(x, x′) V (x, x′) dA π π π Z π S

G(x, x′) V (x, x′) B(x′) = E(x′)+ ρ(x′) B(x) dA (2.25) Z π S Note that E(x) is now the energy per unit area emitted by the surface (not the irradiance).

3 Solving the Radiosity Equation

After deriving the radiosity equation, one can note several interesting features of the equation. First, the unknown, radiosity, appears on both the left side of

10 the equation as well as under the integral on the right. This is an extremely diﬃcult equation to solve and rarely has a closed form solution. Additionally, the function space of the radiosity function is inﬁnite (an inﬁnite number of values are required to completely specify the function). This can be seen by noting that solving the radiosity equation for one point, does not tell us any- thing about the neighboring locations. Therefore, solving the radiosity equation requires either solving the equation for the exact functional form, or computing the radiosity at inﬁnitely many points.

3.1 Finite Element Methods Since both solving for an exact functional form as well as solving for inﬁnite many radiosity values seem unattractive, one must approximate the radiosity equation by a simpler formula before attempting to solve the equation. Finite element methods provide a method for performing this approximation. Finite element methods approximate a complicated function by a linear sum of a ﬁnite number, n, of simpler basis functions, Ni(x), each of which have ﬁnites support. The domain of the function is subdivided into a mesh of elements each contain- ing one or more nodes. The mesh and nodes organize the areas of support for the basis functions.

In the case of radiosity, the domain that is divided is the set of all surfaces in the environment. This leads to an approximation of the radiosity function

n B(x) ≈ Bˆ(x)= BiNi(x) (3.1) Xi=1 There are many diﬀerent basis functions to choose from. The most commonly used in radiosity is the constant basis function

0 if x is outside element i Ni(x)= (3.2) 1 if x is inside element i

3.2 Error Metrics Ideally, we would like the approximation, Bˆ(x) to aggree with the actual ra- diosity solution B(x) everywhere. In general, this is not possible since the approximation, Bˆ(x), is restricted to the ﬁnite dimensional space deﬁned by the linear sum of the basis functions. Therefore, given a set of basis functions, the task is to ﬁnd the coeﬃcients Bi that minimize some error metric deﬁned for the function.

11 The true error is deﬁned by the diﬀerence between the true and approximate solutions

ε(x)= B(x) − Bˆ(x) (3.3) This error metric is impractical to use since it requires the knowledge of the true solution. Instead, one can substitute the approximate solution Bˆ(x) into the radiosity equation

Bˆ(x) = E(x)+ ρ(x) Bˆ(x′) G(x, x′) dA′ (3.4) Z S and deﬁne the residual to be the diﬀerence between the two sides

r(x) = Bˆ(x) − E(x) − ρ(x) Bˆ(x′) G(x, x′) dA′ (3.5) Z S This is equivalent to applying the operator K to the negation of the actual error, where K is deﬁned by the radiosity transport

Kb(x)= b(x) − ρ(x) b(x′) G(x, x′)dA′ (3.6) Z S Where KB(x)= E(x). We can note that the exact solution will make r(x) zero everywhere. Additionally, though Bˆ(x) is restricted to a ﬁnite function space, r(x) is not. Similar techniques to those used above allow us to project the resid- ual into a ﬁnite function space. The goal then becomes ﬁnding a solution that minimizes the ﬁnite dimensional residual.

Similar to the approximation of the radiosity function, we wish to approximate the magnitude of the residual by a linear sum of ﬁnite support functions. These ﬁnite support functions are called weighting functions and the technique is known as a weighted residual method. The weighted residual is then deﬁned as

n |r(x)| = | < r(x), Wi(x) > | (3.7) Xi=1 The residual norm can be minimized by ﬁnding a solution that makes each of the n terms ( < r(x), Wi(x) > ) zero. The next sections discuss two choices of weighting functions, point collocation and Galerkin method, and how they aﬀect the radiosity solution.

12 3.2.1 Point Collocation The easiest weighting functions consist of point sampling delta functions

Wi(x)= δ(x − xi) (3.8)

This is equivalent to requiring the solution to be exact at a given set of points xi. However, r(x) can still be nonzero between these points. As the number of points is increased, the residual is increasingly restricted. Generally, the points, xi, are selected to be the locations of the nodes in the radiosity solution. This is known as point collocation.

For n nodes, there are n constraints that must be met (n places where the residual is driven to zero), and this results in a system of n simultaneous linear equations

′ ′ ′ Bˆ(xi) − E(xi) − ρ(xi) Bˆ(x ) G(xi, x ) dA = 0 (3.9) Z S

Substituting for Bˆ yields

n n ′ ′ ′ Bj Nj (xi) − E(xi) − ρ(xi) Bj Nj (x ) G(xi, x ) dA = 0 (3.10) Z Xj=1 Xj=1 S

Factoring out the unknowns Bj gives

n ′ ′ ′ Bj Nj(xi) − ρ(xi) Nj (x ) G(xi, x ) dA − E(xi) = 0 (3.11) Z Xj=1 S Which can be expressed in matrix-vector from as

KB = E (3.12)

Where the element of the matrix K are given by

′ ′ ′ Kij = Nj (xi) − ρ(xi) Nj (x ) G(xi, x ) dA (3.13) Z S

13 Note that these coeﬃcients are independent of the radiance distribution in the scene and depend solely on the geometry and materials in the scene. This means that these coeﬃcients can be precalculated for the scene before any radiosity calculations begin.

3.2.2 Galerkin Method The previous method of point collocation forces the radiosity solution to be exact at the nodes points only. Alternatively, the weighted residuals method allows one to force the weighted integrals of the residual to be zero. This can be expressed by

< Wi(x), r(x) >= Wi(x)r(x)dA = 0 (3.14) Z S

Substituting for r(x) gives

0= Wi(x)Bˆ(x)dA Z S

′ ′ ′ − Wi(x)E(x)dA − Wi(x)ρ(x) Bˆ(x )G(x, x )dA dA (3.15) Z Z Z S S S

The Galerkin Method chooses the same weighting functions as basis functions (Wi(x)= Ni(x)). This gives

0= Ni(x)Bˆ(x)dA Z S

′ ′ ′ − Ni(x)E(x)dA − Ni(x)ρ(x) Bˆ(x )G(x, x )dA dA (3.16) Z Z Z S S S

Expanding Bˆ and solving for the unknowns Bj gives

n ′ ′ ′ Bj Ni(x)Nj (x)dA − Ni(x)ρ(x) Nj(x )G(x, x )dA dA Z Z Z Xj=1 S S S

14 − E(x)Ni(x)dA = 0 (3.17) Z S

Note that this can again be expressed as a system of linear equations in matrix form

KB = E (3.18)

Where the elements of K are now given by

′ ′ ′ Kij = Ni(x)Nj (x)dA − Ni(x)ρ(x) Nj(x )G(x, x )dA dA (3.19) Z Z Z S S S

And the elements of E are

Ei = E(x)Ni(x)dA (3.20) Z S

3.3 Constant Radiosity Elements While the derivations in the previous two sections are valid for any basis func- tions, several simpliﬁcations can be made if constant basis functions are chosen.

Using the Galerkin Method with constant basis functions yields several drastic simpliﬁcations. The fact that the basis functions are non-overlapping and can only take on values of 1 or 0 reduces the ﬁrst term in equation equation (3.17) as follows

Ni(x)Nj (x)dA = δij Ai (3.21) Z S

By similar reasoning, the emmission term reduces to

E(x)Ni(x)dA = EiAi (3.22) Z S where Ei represents the average emission per area of element i.

15 Additionally, since the basis functions have unit value within the element and are zero otherwise, the domain of integration can be limited to the areas of the corresponding elements:

′ ′ ′ ′ Ni(x)ρ(x) Nj (x )G(x, x )dA dA = ρi G(x, x )dAj dAi (3.23) Z Z Z Z S S Ai Aj

Substituting these simpliﬁcations back into equation (3.17) yields

n ′ Bj δij Ai − ρi G(x, x )dAj dAi − EiAi = 0 (3.24) Z Z Xj=1 Ai Aj

Divding by Ai and moving terms gives

n 1 ′ Bj δij − ρi G(x, x )dAj dAi = Ei (3.25) Ai Z Z Xj=1 Ai Aj or more succintly

n Bj [δij − ρiFij ]= Ei (3.26) Xj=1 where Fij is deﬁned as

1 ′ Fij = G(x, x )dAj dAi (3.27) Ai Z Z Ai Aj

Fij is called the form factor and represents the fraction of energy leaving ele- ment i that arrives directly at element j.

The classical discrete radiosity equation is found by rearranging terms to arrive at

n Bi = Ei + ρi Bj Fij (3.28) Xj=1

16 This equation is somewhat hard to interpret physically. We can convert this equation to a more physically intuitive form by multiplying through by Ai

n BiAi = EiAi + ρi Bj Fij Ai (3.29) Xj=1 and noting the reciprocity between form factors

Fij Ai = FjiAj (3.30) to derive

n BiAi = EiAi + ρi FjiBj Aj (3.31) Xj=1 The physical interpretation of this equation is that the total power leaving ele- ment i, BiAi, is equal to the power emmitted from the surface, EiAi, plus the power reﬂected from the surface. The power reﬂected from the surface depends upon the power leaving all other elements that arrives directly at element i, FjiBj Aj and the reﬂectivity of the surface, ρi.

3.4 Matrix Solutions The previous sections described how to approximate the radiosity equation by a system of linear equations of the form

KB = E (3.32) where the matrix K can be separated into the diﬀerence of an almost diagonal matrix, M, and the product of the matrices P and F

[M − P F ] B = E (3.33)

For constant radiosity elements, M is simply the identity matrix I. The matrix P is a diagonal matrix of the elements’ reﬂectivities, and the matrix F is the matrix of form-factors.

There are several interesting features to notice about the matrix K

• Size: Generally, the matrix will be square and n x n, where n is the number of basis functions used to approximate the radiosity function.

17 • Sparsity: In general, the matrix will be more full than sparse. The ijth element of K will be zero only if the reﬂectivity of the surface is zero (the surface is completely black) or if the elements are completely invisible to each other (Fij then becomes zero). However, many times it is possible to determine completely independent sets of elements (elements in a set do not interact with elements outside of the set – such as two completely separate rooms) causing the matrix to become block diagonal. At this point, the matrix can be separated into two smaller matrices and each solved separately.

• Symmetry: The matrix K is not symmetric in general since kij 6= kji. However, one can make a transformation to the system to make the matrix K symmetric. Since Fij Ai = FjiAj , one can premultiply the ith row (equation) by Ai to enforce symmetry. This allows one to use solution techniques that rely on the matrix K being symmetric. • Diagonal Dominance: A matrix is diagonally dominant if the absolute value of the diagonal element is greater than or equal to the sum of the absolute values of the oﬀ-diagonal elements. More formally

n |Kij | ≤ |Kii| , ∀i (3.34) j=1X,j=6 i

This can be shown to be true for constant radiosity elements, since Kii is one and the sum of form factors is by deﬁnition equal to one and the reﬂectivities must be less than or equal to one (in a physically correct system). Diagonal dominance is useful in that it ensures convergence for many iterative methods (such as Gauss-Seidel in the following section). • Spectral Radius: The spectral radius is a speciﬁc matrix norm that mea- sures the size of the largest eigenvalue. This indicates the speed at which iterative methods will converge. Lower values for the spectral radius in- dicate faster convergence. For the radiosity problem, one can see that if the reﬂectivities of the objects are increased, then more iterations are required to converge. This is because more and more light reﬂects around the scene. The mathematical result is that the spectral radius approaches 1. • Condition: The condition number of a matrix indicates how sensitive the solution is to small perturbations. For the radiosity problem, the matrix is usually well conditioned.

The following sections will examine iterative techniques to solve the radiosity matrix equation.

18 3.4.1 Gauss-Seidel In iterative methods, an initial approximation of the solution is made, and then continually updated using the matrix equation until the approximation con- verges to within a tolerence of the true solution.

The simplest iterative scheme, Jacobi Iteration, updates the one entry in the solution approximation by assuming all of the other entries are correct. The matrix equation is solved for the entry to be updated and the current estimates are used to update it. For the radiosity solution, one step, or element update, consists of the following equation

(k) (k+1) Bj Bi = Ei − Kij (3.35) Kii Xj=6 i

Note that the superscripts indicate the iteration number.

A slightly more complex method, the Gauss-Seidel Iteration, uses the most recently computed solution vector at each step, rather than using the solution vector calculated at the previous iteration. This yields the following formula for each step of the radiosity solution

i−1 (k+1) n (k) (k+1) Bj Bj Bi = Ei − Kij − Kij (3.36) Kii Kii Xj=1 j=Xi+1

One update step of the Gauss-Seidel algorithm involves updating a single radios- ity value, Bi, by summing the contributions from all other radiosity elements, Bj , weighted by the appropriate reﬂectivities and form factors (in row i). This is physically equivalent to gathering the light from all other elements to compute the updated estimate Bi.

3.4.2 Progressive Reﬁnement

The Gauss-Seidel algorithm updates a single radiosity value, Bi, by considering all of the contributions on row i. An alternative approach is to update all el- ements due to a single radiosity element’s contributions along a column. This is equivalent to shooting out the energy from a patch Bi to all other patches weighted by the reﬂectivity and form factors given in column i.

Cohen et al. describe a variation on this type of algorithm known as progressive reﬁnement. At each step, the patch containing the largest amount of unshot radiosity is chosen to “shoot” its radiosity to all other elements (weighted by

19 the appropriated column coeﬃcients). By choosing the element with the largest unshot radiosity, the algorithm is able to use the element that will cause the greatest change in scene as a whole. This allows the approximation to approach the true solution after only a few steps.

Pseudocode for the progressive reﬁnement algorithm is given below.

Progressive Reﬁnement forall i Bi = Ei; ∆Bi = Ei; while not converged ﬁnd i such that ∆BiAi is largest; forall elements j ∆rad = ∆Bi ρj Fji; ∆Bj = ∆Bj + ∆rad; Bj = Bj + ∆rad; ∆Bi = 0; Display the image using the current values of Bi;

The following ﬁgure shows the a comparison of the two techniques. (Figure 5.7)

4 Hierarchical Radiosity

One can see from the following sections that the cost of solving the discrete radiosity equation depends heavily on the number of elements since the interac- tion between each pair of elements must be computed. This is expensive since for each interacting pair, a costly form factor computation must be performed. One way to reduce this computational load is to reduce the number of elements. An alternative to this approach is to reduce the number of relationships (form factors) computed. For instance, two groups of elements separated by a large distance may approximate the interaction between all pairs of individual ele- ments by a single value computed once for the two groups. This requires a hierachy of elements as well as a hierarchy of interaction and is the topic of hierarchical radiosity.

Consider the following physical example. Image a room with a table supporting several small objects. Light reﬂected from the table top aﬀects the illumination of a wall in the room. However, the illumination of the wall will not vary sig- niﬁcantly if the objects on the rearranged. Noting this, the contribution of the table top to the wall can be represented by a single average value, as oppossed

20 to computing individual contributions from many small table top elements.

However, when the table top is rendered in the ﬁnal image, the variation in illu- mination must capture all the small lighting details upon its surface (shadows, etc.). These details will be lost if the illumination arriving at the table is average over the entire surface by treating the table top as a single receiving element. This shows that the radiosity should be represented by at least two levels of subdivision, coarsely for when the surface acts as an illumination source, and ﬁnely when it acts as a receiver. This observation inspired the two-level hierar- chical radiosity algortihm.

4.1 Two-Level Hierarchical Radiosity The two-level method for radiosity (Cohen et al.) divides surfaces based on the observation of the previous section. Two levels of the hierarchy are created: coarsely subdivided patches to represent when the surfaces act as are sources of illumination, and a ﬁner subdivision of the patches into elements for when the surfaces act as receivers. Elements can be adaptively subdivided, but patches are speciﬁed a priori by the user.

The steps of the algorithm are as follows:

1. Divide the surfaces into m patches and n smaller elements (m<

Aq Fij = Fqj (4.1) Ai Xq∈i

4. Solve the m x m system for the patch radiosities:

m Bi = Ei + ρi Bj Fij (4.2) Xj=1

5. Back solve for element radiosities, by expressing the element radiosity as the sum of contributions from each patch:

m Bq = Eq + ρq Bj Fqj (4.3) Xj=1

21 6. If the radiosity of neighboring elements is widely varying, the elements can be adaptively subdivided. New element-to-patch form factors are computed only for the new elements. The element radiosity can then be calculated from the original patch radiosities. This step can be performed repeatedly until a satisfactory solution is found.

While the two-level hierarchy reduces the number of form factor computations, it does impose certain restrictions. First, The groupings of elements into patches is static. That is, the elements in the group are assumed to act similarly for all interactions in the scene (with other patches near to the group as well as far away). Secondly, the patches cannot be grouped together, only elements. This results from the distinction made between sources and receivers. Finally, the user is required to specify the patch level subdivision. These limitations will be addressed in the multi-level hierarchy of the next section.

4.2 Multi-Level Hierarchical Radiosity In order to remedy the aforementioned problems, Hanrahan et al. generalized the two-level hierarchy to multiple levels. This allow receivers as well as sources to be computed at the appropriate levels of detail. The multilevel hierarchy structure resmebles that of a quadtree, with each parent node subdividing into four child nodes.

Within this hierachy, nodes at any level may be linked. This linking structure represents the shooting interaction from all leaf nodes under the source node to all leaf nodes under the destination node. Therefore, energy can be shot from any node in the hierarchy to any other node in the hierarchy. Since these non- leaf nodes represent groups of leaf nodes, the energy received by a non-leaf node must later be inherited by the leaves. These groupings, as well as the ability to shoot from/to any node in the hierarchy, will reduce the total number of form factors that need to be calculated. In fact, it can be shown that only O(n) form factors need be computed for a given error.

Unlike previous algorithms, multi-level hierarchical radiosity does not explicitly build a matrix. Instead, the surfaces are subdivided and the links are built as needed. The links represent the interaction of one set of elements to another set. Therefore, the links hold the form factors while the quadtree nodes hold the radiosity and emission values.

The basic structure of the hierarchical algorithm is given below.

BasicHierachicalRad(ﬂoat Fǫ) forall(surfaces p) p → Bs = p → E;

22 forall(surface pairs (p,q)) ReﬁnePatch(p,q,Fǫ); while(not converged) forall(surfaces p) Gather(p); forall(surfaces p) PushPull(p);

The hierarchical algorithm begins by calling ReﬁnePatch to subdivide the sur- faces and create the appropriate links. The pseudocode for ReﬁnePatch is given below.

ReﬁnePatch(Quadnode *p, Quadnode *q, ﬂoat Fǫ) Quadnode *r; if(Oracle1(p,q,Fǫ)) Link(p,q); else if(Subdiv(q)) foreach(child r of q) ReﬁnePatch(p,r,Fǫ); else if(Subdiv(p)) foreach(child r of p) ReﬁnePatch(r,q,Fǫ); else Link(p,q);

Oracle1(Quadnode *p, Quadnode *q, ﬂoat Fǫ) Quadnode *r; if(p → Area < Aǫ AND q → Area < Aǫ)) return TRUE; if(estimateFormFactor(p,q) < Fǫ) return TRUE; return FALSE;

ReﬁnePatch begins by asking an oracle function whether or not the two patches should be linked. If so, it simply calls Link(p,q) which actually builds a link data structure and computing the appropriate forrm factor. Otherwise, the ReﬁnePatch function tries to subdivide the receiving patch, q, with the Sub- div procedure. Subdiv will return whether or not hte patch can be subdivided (usually based on minimum area or maximum quadtree depth criteria) and sub- divides if necessary. Therefore, if q can be subdivided, ReﬁnePatch does so, and calls itself recursively on the newly created child patches. If q cannot be sub- divided, this process is attempted on patch p. If this fails, the algorithm must create a link between patches p and q.

Now that the environment has been properly subdivided and the appropriate links created, the radisoity system can be solved. This consists of calling two

23 functions, Gather and PushPull, until the system converges. The pseudocode for these functions is given below.

Gather(QuadNode * p) QuadNode *q; Link *L;

p→ Bg = 0; foreach( gathering link L of p) p→ Bg += p→ ρ * L→ Fpq * L→ q → Bs;

foreach(child r of p) Gather(r);

PushPull(QuadNode *p, ﬂoat Bdown = 0.0) ﬂoat Bup, Btemp;

if(p is a leaf) Bup = p → E + p → Bg + Bdown ; else Bup = 0; foreach(child r of p) Btemp = PushPull(r, p→ Bg + Bdown); r→Area Bup += Btemp * p→Area p → Bs = Bup; return Bup;

The Gather function gathers the energy over all incoming links. The shooting radiosity at one end of the link (Bs) is converted to gathered radiosity (Bg) at the other end.

The PushPull function tells the other nodes in the tree about energy gathered at other nodes node the previous gather step. It does so by ﬁrst pushing all of the received energy down the tree to the children (so children know all the en- ergy that was received above them), and then pulling the resulting energy back up the quadtree via area averaging (so parents know about the energy of all nodes below them). One can see that on the way down, the gathered radiosity is accumulated (in Bdown). Once a leaf is reached, it adds its own emmission and gathered radiosity and returns it up the tree. On the way back up the tree, these child radiosities are area averaged to compute the value for the parent nodes. Finally, these computed radiosity values are stored in Bs to prepare for the next gathering step.

24 4.2.1 Progressively Reﬁning the Hierarchy The hierarchical radiosity algorithm described above makes decisions about sub- division and link creation based solely on the geometry of the system. This sys- tem does not take into account how much energy will eventually travel accross these links. We could do better if we also reﬁne these links (and subdivisions) after we have some idea of the energy transfer between the elements. The pseu- docode for a progressively reﬁned hierachical solution is given below.

HierarchicalRad(ﬂoat BFǫ) Quadnode *p, *q; Link *L; forall(surfaces p) p→ Bs = p→E; forall(surface pairs (p,q)) ReﬁnePatch(p,q,BFǫ); while(not converged) forall(surfaces p) Gather(p); forall(surfaces p) PushPull(p); forall(links L) ReﬁneLink(L,BFǫ);

The only addition to the previous algorithm, is that now we adaptively reﬁne the links (and therefore the subdivision) as the solution progresses. The pseudocode for reﬁning the links is as follows:

ReﬁneLink(Link *L, ﬂoat BFǫ) int subdivision = FALSE; Quadnode *p = L→p; Quadnode *q = L→q;

if(Oracle2(L, BFǫ)) subdivision = TRUE; unlink(L); if(Subdiv(q)) foreach(child r of q) Link(p,r); else foreach(child r of p) Link(r,q); return subdivision;

When reﬁning a link, one simply asks an oracle if the link needs to be reﬁned (Oracle2). If so, the algorithm attempts to subdivide node q and link with the newly created children. If node q cannot be subdivided, node p is tried. Finally, if neither node q or p can be subdivided, or if the oracle decideds not to reﬁne

25 the link, the function simply exits.

The Oracle2 function plays an important role in that it decides when to reﬁne a given link. Reﬁning too often will result in excess computation while reﬁning too little will result in inaccurate radiosity function approximations. A commonly used oracle is given below. This oracle simply checks if the two nodes, p and q, are already too small for further reﬁnement, whether there is no radiosity to be shot, or whether the total energy sent across the link is extremely small. If any of these cases hoold, the link does not need reﬁning, otherwise, the oracle claims that it does.

Oracle2(Link *L, ﬂoat BFǫ) QuadNode *p = L→p; QuadNode *q = L→q;

if(p→ Area < Aǫ AND q→ Area < Aǫ) return FALSE; if(p→ Bs == 0.0) return FALSE; if(p→ Bs * p→Area * L→L→ Fpq < BFǫ) return FALSE; return TRUE;

The above progressive reﬁnement hierarchical radiosity algorithm allows the synthesis of images of complex scenes with a greatly reduced computation cost. However, much research is still needed in the ﬁeld of radiosity and image syn- thesis in general.

References

[Kaj86] Jim Kajiya. The Randering Equation. In SIGGRAPH 86 Conference Proceedings, pages 143–151, July 1986.

26