• No results found

Real-time Radiosity

N/A
N/A
Protected

Academic year: 2021

Share "Real-time Radiosity"

Copied!
106
0
0

Loading.... (view fulltext now)

Full text

(1)

Real-time Global Illumination of a Static Scene with Dynamic Lights using Hierarchical Radiosity

MAGNUS BURENIUS

Master’s Thesis at NADA Supervisor & Examiner: Lars Kjelldahl Supervisor at Avalanche Studios: Gustav Taxén

TRITA xxx yyyy-nn

(2)
(3)

This thesis investigates how to compute the physical cor- rect illumination of a virtual 3d-scene. Global Illumination is simulated, i.e. the light gets reflected multiple times, possible infinite. The goal is to achieve real-time Global Illumination of a static scene with dynamic light sources.

The Radiosity algorithm is investigated and adjusted for real-time. The algorithm is derived in detail to stress its physical correctness. Methods to numerically solve the re- sulting equation systems are discussed like: gathering, Ja- cobi and Gauss-Seidel Relaxation. The ability to use in- formation from the previous frame when computing the following is emphasized in the discussion of Gauss-Seidel Relaxation.

Methods of accelerating the algorithm using hierarchies and clusters are explored and Hierarchical Radiosity [9] is im- plemented for a real-time application. See section 11 for the main results. Face Cluster Radiosity and Vector Irradiance [15] are also discussed. We end by discussing the benefits of using a precalculated inverse solution and various ways of improving the performance.

(4)

Detta exjobb undersöker hur man kan beräkna ljuset i en tredimensionell miljö på ett fysikaliskt korrekt sätt. Så kallad Global Illumination simuleras, dvs. man låter ljuset reflek- teras runt godtyckligt antal gånger i miljön. Målet är att simulera Global Illumination i realtid för en statisk miljö med dynamiska ljuskällor.

Mer specifikt är det Radiosity-metoden som undersöks och anpassas för att fungera i realtid. Metoden härleds i detalj för att visa att den är fysikaliskt korrekt. Vidare diskuteras metoder för att numeriskt lösa de ekvationssystem som up- pstår som: gathering och Jacobi- och Gauss-Seidel-relaxation.

Förmågan att använda information från föregående bildru- ta när nästa ska beräknas betonas i diskussionen av Gauss- Seidel-relaxation.

Det undersöks även hur man kan accelerera algoritmen genom att dela in miljön i hierarkiska kluster. Särskilt im- plementeras Hierarchical Radiosity [9] och anpassas för re- altid. Face Cluster Radiosity och Vector Irradiance [15] un- dersöks också. Slutligen diskuteras fördelarna med att an- vända en förberäknad invers och ytterliggare sätt förbättra prestandan.

(5)

1 Introduction 1

1.1 Avalanche Studios . . . 2

1.2 Master Thesis at Avalanche Studios . . . 2

1.3 Method . . . 2

1.4 Structure of the Report . . . 3

I Background 5 2 3D-Computer Graphics 7 2.1 Real-Time 3D-Graphics in Games . . . 7

2.2 Pre-rendered Graphics . . . 7

2.3 Local and Global Illumination . . . 8

2.4 Shades and Shadows . . . 9

2.5 Color Bleeding . . . 10

3 A first glance at Radiosity 13 4 Physically Based Rendering 17 4.1 Quantities and Concepts . . . 18

4.1.1 Solid Angle . . . 18

(6)

4.1.8 Conservation of Radiance Along a Ray . . . 22

4.2 Diffuse Reflection . . . 26

4.3 Diffuse Rendering Equation . . . 27

4.3.1 Hemisphere Formulation . . . 27

4.3.2 Area Formulation . . . 28

4.3.3 Discreet Area Formulation - Radiosity Equation . . . 30

4.4 Form Factors . . . 32

4.4.1 Monte Carlo Integration . . . 33

4.4.2 Form factor application of Monte Carlo . . . 33

4.4.3 Reciprocal Relation . . . 34

5 Matrix Formulation 37 6 Solving the System Using Gathering 39 II Adjusting Radiosity for Real-time 41 7 First Implementation 43 7.1 Assumption for Real-time Radiosity . . . 43

7.2 Direct Light to the Patches . . . 43

7.3 Creation of Patches . . . 45

(7)

7.5 Patch Data . . . 46

7.6 Steps of the Algorithm . . . 47

8 Jacobi and Gauss-Seidel Relaxation 51 8.1 Theory . . . 51

8.2 Application . . . 53

9 First Results 55 10 Hierarchies and Clusters for Radiosity 57 10.1 Hierarchical Radiosity . . . 57

10.1.1 Links . . . 59

10.1.2 Building the Hierarchy . . . 61

10.1.3 Tree of Patches . . . 62

10.1.4 Complexity . . . 63

10.1.5 Using the Hierarchy to Solve the System . . . 63

11 Main Implementation and Results 65 11.1 Parameters . . . 66

11.2 Images . . . 67

11.3 Discussion of Results . . . 75

IIIFuture Improvements 77 12 General Clusters and Hierarchies 81 12.1 Face Cluster Radiosity & Vector Irradiance . . . 81

12.2 Volume Clusters . . . 82

(8)

13.3 Using the Inverse with Iterative Ideas . . . 90

14 Further Improvements 91 14.1 GPU . . . 91

14.2 Treating Sending and Receiving Patches Differently . . . 92

14.3 Combining with Ambient Occlusion . . . 93

14.4 Discontinuity Meshing . . . 93

15 Conclusion 95

Bibliography 97

(9)

Introduction

There exists several methods for calculating the illumination of a 3d-environment.

Some are capable of handling completely dynamic environments in real time, but those methods are often very approximate. Typically only direct lighting is taken into account, i.e. light that comes directly from a light source to a surface without being reflected by another surface on the way. In reality, light is reflected all around an environment and a surface is also lit indirectly by light that may have been reflected several times before reaching the surface. Ignoring the indirect light makes the resulting images look somewhat artificial and much of the characteristics of real world lighting with all its vivid colors and shades is thereby lost. Simulating indirect light accurately is however very costly and traditionally not suitable for real time applications. This is due to the global nature of indirect light, i.e. light that illuminate a specific point of a surface may have been reflected all over the scene before reaching that point. One therefore speaks of Global Illumination when it comes to simulate indirect lighting accurately.

Radiosity [13, 2] is an algorithm for simulating indirect illumination which uses the simplifying assumption that all surfaces are ideal diffuse reflectors. A point on such a surface looks the same regardless of viewing direction, i.e. it is not glossy at all. Radiosity is a finite element method and all surfaces of the 3d-environment are discretized in suitable large patches. The light is then propagated between these patches. How to discretize the scene in an optimal way is far from trivial.

Larger patches means a faster algorithm but a more approximate solution. One therefore need to find out which parts of the scene that need a fine discretization and which that do not. Algorithms have also been developed that groups the patches in hierarchies and clusters and use different discretizations for different light interactions. The idea is that small interactions, e.g. between distant surfaces, do not have to be calculated with the same accuracy as larger ones.

(10)

Studios is to be world leading in games technology and it is therefore essential to actively search for new ways of improving their graphic systems.

1.2 Master Thesis at Avalanche Studios

A number of recent (fall 2007) game titles like Crytek’s Crysis and Guerrilla’s Killzone 2 feature some form of dynamic global illumination. We can assume that dynamic global illumination will be taken for granted in indoor game environments very soon. The straightforward static radiosity/lightmap approach [1] is already considered to be an absolute minimum for any realistic-looking indoor game, and after the release of Valve’s Half-Life 2 it is also expected that dynamic objects in a static environment will receive their ambient light from the radiosity solution, e.g.

via light probes [8]. The challenge, then, is to update the global illumination solution in real-time, allowing for movement of light sources and objects. The problem may be tackled in several ways. This Master Thesis will look into the possibility of using radiosity and different hierarchies and clusters for real time illumination of a static scene by dynamic light sources. Questions to be addressed:

• Can hierarchical and cluster algorithms be combined to do real time calcula- tions of indirect illumination in a reasonably complex environment?

• Can the methods be combined with other methods to increase quality and/or performance?

• Is it possible to handle dynamic objects? If so, how?

1.3 Method

The work on the master thesis will begin with a general study of literature on the topic. An implementation of classical radiosity, i.e. without any accelerating algorithms, will be developed to get a good understanding of the basic algorithm and all its steps. The implementation will be written in C++ and Microsoft’s Direct3D will be used for basic graphics. This is followed by an analysis of the basic

(11)

algorithm and its implementation to see which steps that need to be improved if real-time performance is to be possible.

After this initial phase, a more in-depth study of Hanrahan & Salzman’s “A Rapid Hierarchical Radiosity Algorithm”[9] follows, which seems to be the most promising algorithm a priori. It builds a hierarchy of patches, i.e. the discretized surface elements, to minimize the number of interactions/dependencies between different patches. The fewer interactions, the faster simulation. An implementation of this algorithm is written and the overall analysis proceeds based on the results so far.

Further algorithms are then studied and evaluated.

1.4 Structure of the Report

This report is structured in three larger parts titled: Background, Adjusting Ra- diosity for Real-time & Future Improvements

The background part first gives an introduction to 3D-computer graphics and the concepts of local and global illumination. The reader may skim or skip this if already familiar with the subject. This is followed by a thorough derivation of the radiosity method, leading to the radiosity system of linear equations: equation 4.15 in subsection 4.3.3. This is the central equation in this thesis. It describes the global illumination of a scene. The subject of this thesis is to solve this equation in real-time. The derivation of the equation may be skimmed if the reader is not a theorist and accepts the equation without understanding it in detail. But it is of course rewarding to understand the derivation as this gives deeper insights into the problem.

The second part discusses how the well-known radiosity method may be adjusted for real-time usage, which is not well-known. It is specifically described how to adjust the hierarchical radiosity algorithm, described by Hanrahan et al. [9]. First an implementation that does not utilize any hierarchies is written and evaluated.

Then the hierarchies are studied and implemented and the benefits of using them are evaluated. In this section the main results of the thesis are presented and illustrated with several images.

This is followed by the part discussing future improvements. Here promising ideas are discussed without being implemented. The thesis ends with a discussion of overall conclusions.

Throughout the report italics is generally used for emphasis. To point out if a certain expression or piece of text is of extra importance.

(12)
(13)

Background

(14)
(15)

3D-Computer Graphics

2.1 Real-Time 3D-Graphics in Games

Video and computer games has ever since their uprising been one of the main forces behind the development of new technology and algorithms for real time computer graphics[1]. The games often take place in large and ever more complex virtual 3d-worlds, and the visualization of these 3d-worlds is of great importance for a captivating game experience. The various degrees of real time performance needed for the interactions and visualizations of the game, clearly limit the acceptable cost of the algorithms that may be used for graphics. For an interactive experience the graphics most probably has to be updated with a frequency of 20-60 images per second, leading to only coarse approximating algorithms being fast enough.

2.2 Pre-rendered Graphics

In computer animated movies like Pixar’s "Finding Nemo" or the special effects in Peter Jackson’s "The Lord of the Rings" and ”King Kong”, this interactive real time aspect is not present. Although the movies themselves may have an update frequency of 30 frames per second, these frames can be computed in advance since they are fully deterministic. This leads to computational times of several minutes being acceptable for every frame. For this reason, graphics in computer animated movies may be more advanced and capture lighting phenomenons much more real- istic than graphics in interactive games. Most commonly various forms of so-called Raytracing [6, 4, 11] are being used for these sorts of pre-rendered animations.

One can also think of applications where not an animation, but only a single or very few images are needed, e.g. architectural visualizations of a room or a building

(16)

Figure 2.1. A pre-rendered image showing off direct and indirect light. Only parts of the window and sofa are lit directly by the sun. The rest of the scene is lit indirectly, by light that may have been reflected several times. Image courtesy of Shams Jorjani.

yet to be built (figure 2.1). In those cases a computational time of several hours may be acceptable for a single image, and intense computations based on physically very accurate lighting models can be carried through. Radiosity, Path Tracing and Photon Mapping [4, 11, 6] are some of those high quality algorithms that manages to accurately calculate the lighting interactions within the virtual 3d-environment.

These algorithms are by nature too demanding for real-time applications like games.

Nevertheless there exists algorithms that accelerate the performance of those compu- tational heavy algorithms [9, 2, 14, 12, 15]. This paper shall examine Radiosity and such accelerating algorithms to see if it is possible to reach real-time performance for a simple, but in a game context adequate 3d-environment. The idea is that even a very coarse and therefore fast Radiosity solution may capture certain important lighting phenomena significantly better than classical real time algorithms.

2.3 Local and Global Illumination

The one thing that makes images created with Radiosity more realistic and more computational heavy, is the global nature of the algorithm. Most algorithms for

(17)

Figure 2.2. The difference between just using direct illumination and radiosity which also takes the indirect lighting into account, i.e. several bounces of light.

Image courtesy of Hugo Elias.

real-time 3d-graphics are more or less local, and this is what makes them fast [1].

By local it is meant that computations only involve local parameters. When the lighting is to be calculated at any given point, only local parameters at that specific point have influence on the result. Examples of such local parameters are the color of the point (albedo), the distances from the point to the light sources, the angles between the surface normal at the point and the vectors to the light sources etc.

Light is assumed to only propagate from a few well defined light sources, directly to all surface points in the scene. This distinction only takes into account the direct illumination from the light sources. In reality, light may also reach a surface point after being reflected by several other surfaces (figure 2.1 & 2.2). A scene is thereby lit indirectly by potentially all surface points in it. This indirect illumination is not captured if only a local lighting model is being used. Ignoring the indirect illumination makes local models fast, but it also makes the resulting images look somewhat artificial and much of the characteristics of real world lighting with all its vivid colors and shades are lost. Making a global illumination model like Radiosity fast enough for real time use is therefore an ever present dream of the computer graphics community.

2.4 Shades and Shadows

Although modern real time 3d-graphics algorithms are very local, they still have some global elements, e.g. calculating shadows from direct light sources. Shadows are a very global phenomenon since if it is to be determined whether any arbitrary surface point is in shadow or not, with respect to a specific light source, one has to

(18)

Figure 2.3. Left: direct lighting. Right: direct + indirect light. Notice the color bleeding in the right image.

know whether any other surface is between the light source and the surface point.

Many real time techniques for handling shadows have been developed, shadow maps [1] being one of the most popular. Still, although the algorithms do some global considerations, the resulting shadows will typically be very sharp. This is because the light is generally only assumed to propagate directly from the main light sources, not indirectly from every singly surface point. Only the shadows from the direct illumination will be captured. All surface points in the scene will, more or less, be characterized in a discreet way as being in shadow or not, with respect to the direct light sources. In reality since all surface points are in a sense indirect light sources, there are infinitely many light sources which one may be in shadow with respect to. This results in a continuous degree of shades and diffuse shadows. For instance corners of a room may be a bit darker then the rest of the walls, although they are not directly in any more shadow than the walls. This continuous degree of shades and shadows is one important characteristic for making artificial images look realistic (figure 2.1 & 2.2). One of the main advantages of Radiosity is its ability to handle this lighting feature as opposed to more local and faster methods. See figure 2.2.

2.5 Color Bleeding

Another phenomenon due to indirect illumination is color bleeding. This is the effect of a surface affecting nearby surfaces by its color (albedo). When light reaches a surface, some of it gets reflected and some of it gets absorbed. A colored surface absorbs less of the light with wave lengths corresponding to the surfaces color.

Therefore the reflected light from the surface will be colored, i.e. have more photons

(19)

of a specific wavelength, which is why we recognize the surface as being colored.

Since all surfaces reflects light, the surfaces nearby a colored surface will be lit indirectly with colored light. The color seem to bleed out into its surroundings. See figure 2.2 and 2.3.

In reality this effect is quite subtle and it is something which we are often not aware of. The human brain automatically compensates for the effect and interprets the result as if there was no color bleeding. Nevertheless, not taking this effect into account is often what makes computer rendered images look artificial and sterile.

One may get the impression that there is something unnatural about an image without being able to point out exactly what. Color bleeding makes the lighting, and its colors, in an image vary more smoothly and it enhances the appearance of an object really being in its environment, not just put on top of it in the final image.

Color bleeding is thus one reason for using a global illumination algorithm such as radiosity.

(20)
(21)

A first glance at Radiosity

Radiosity [2, 13] is a physically accurate model which can be used for simulating global illumination. It is a finite element method originating from the 1950s and the field of radiative heat transfer. It was originally developed to simulate heat transfer for satellites and other craft used for space exploration. In 1984 the ap- plication of radiosity for computer graphics was realized and radiosity as a global illumination algorithm was developed at the universities of Cornell, Fukuyama and Hiroshima. Essentially the radiosity method comes from considering energy balance and deriving and solving a system of linear equations.

The word radiosity is also the name of the physical quantity for power of light leaving a surface at a given point, per unit areaJ s−1m−2(figure 3.1) . This quantity can be coupled to how bright or dark we perceive the surface. Color is taken into account by the fact that the radiosity is generally different for different wavelengths of light. A surface which we perceive as blue has a higher radiosity corresponding to that wavelength of light. Usually in computer graphics, one represents color by three different values corresponding to its red, green and blue component. In the same spirit one may keep track of the propagation of colored light within a scene, by treating the red, green and blue light separately. The three components are in principle treated in the same way, but separately, and hereafter only a general component will be mentioned explicitly in this text.

Generally a point on a surface may look different if it is viewed from different angles. What we see of the surface is the light that comes from it. The surface reflects light and this light will generally come from different angles if the surface is viewed from different angles. This is what makes a surface look shiny and glossy.

The more glossy surface the more this is noticed. For a perfectly glossy surface, i.e.

a mirror, the light reflected will have the same reflection angle as incident angle. An object might also be transparent. Since a specific surface point might look different

(22)

Figure 3.1. Light leaving a surface. The physical quantity radiosity stands for the energy of light leaving a surface per unit time per unit area

J s−1m−2 .

depending on what angle it is viewed from one needs to know the light leaving all points in all directions to know the complete illumination of a scene.

Under those general circumstances the radiosity of a surface point does not give all the information needed. If the radiosity of a surface point is known, only the total light leaving that point per unit area is known. How much of that light that goes into different directions is not known. In general there is thus not a direct connection between the radiosity of a surface point and how we see it.

Radiosity Assumption To simplify things the radiosity algorithm assumes all surfaces to be completely opaque and ideal diffuse. This is the key characteristic of the algorithm. An ideal diffuse surface is not glossy at all. A point on it looks the same from all directions. In a sense it is the opposite of a mirror. This leads to a direct connection between the total light leaving a surface point, i.e. radiosity, and how we see it. Since the light leaving an ideal diffuse surface point will be the same in all directions it is sufficient to deal with just one value per point, not one for every direction. The complete illumination of a scene is then known if the radiosity of every surface point is known.

Since there are infinitely many points on every surface, the first step of the algorithm is to reduce this infinite set of points to a finite representation, on which it is easier to do the calculations. The most straightforward way of doing this is to first tessellate all surfaces into many flat polygons and then subdivide these polygons until they are small enough for the radiosity to be assumed as constant over them. These small surface elements with constant radiosity are called patches. Figure 3.2 shows a scene consisting of triangular patches.

Every patch will receive light from possible every other. By considering energy balance in the scene a system of linear equations can be derived, with the radiosity of the patches as unknowns. A patch’s radiosity depends linearly on every other visible patch’s radiosity. A solution of the system can be calculated using iterative

(23)

interpolated linearly between patches when drawn.

so-called relaxation methods. When the radiosity of each patch has been calculated, the solution can be displayed by using standard methods for drawing 3D-polygons on a 2D-screen. This drawing step may utilize graphic libraries like Microsoft’s Direct3D or OpenGL for fast hardware acceleration.

The most expensive part of the radiosity algorithm is calculating the coefficients of the system of linear equations, governing the radiosity of the patches. For all pairs of patches, these coefficients tell how much of the light leaving the first patch that reaches the second patch. If there are n patches, then there are n2such coef- ficients and each takes time O(log n) to calculate, yielding a total time complexity of O(n2log n) for calculating all coefficients.

If the scene geometry is assumed static but the lighting within the scene changes, these coefficients can mostly be reused. This gives a glimpse of hope for acquiring real time performance for radiosity. Accepting the scene geometry to be static, most part of the coefficients can be pre-calculated and illumination of the scene by varying lighting conditions might be possible to achieve in real time. This way of using readiosity for real-time global illumination will be described in greater detail in part II. The next section will give a more in-depth discussion and derivation of the classical radiosity algorithm.

(24)
(25)

Physically Based Rendering

Radiosity is an algorithm which can produce very realistic images. This is because it models the interaction of light in the scene in a physically accurate way. This section will explain how it works and the physical quantities and concepts needed to do that.

The goal of the section is to reach a derivation and explanation of the discrete diffuse rendering equation, which is simple just called the radiosity equation (equation 4.15 in subsection 4.3.3). This is the central equation in this thesis. It describes the global illumination of a scene. The derivation of the equation may be skimmed if the reader is not a theorist and accepts the equation without understanding it in detail. But it is of course rewarding to understand the derivation as this gives deeper insights into the problem.

Figure 4.1. Solid Angle

(26)

Figure 4.2. Hemisphere above a surface point

4.1 Quantities and Concepts

4.1.1 Solid Angle

For a theoretical derivation of the radiosity algorithm the concept of solid angle is required. A usual angle can be described as the length of an arc of the unit circle.

Assume being at a specific point in a two dimensional world, like R2, looking at an object. The view angle, measured in radians, that the object occupies from this point of view is the length of the arc that one gets from projecting the object to the unit circle. Solid angles is used to extend the concepts of view angles to three dimensions. If one looks at an object in a 3d-world, like R3, from a specific point, the solid angle that the object occupies is the area of the segment that one gets by projecting the object to the unit sphere (figure 4.1). The infinitesimal solid angle dω subtended by an infinitesimal surface area da may be written as:

dω = |ˆr · ˆn| da r2 =

ˆr · ¯da

r2 = r · ¯¯ da

r3 (4.1)

r =|¯r|

r =ˆ rr¯ da = ˆ¯ nda

where ¯r is the vector from the point of view to the surface point and ˆn is the normal of the surface at that point. ˆr thus points in the direction of the surface point and r is the distant to it.

4.1.2 Hemisphere

Consider a point on a surface. If the surface is smooth it will be planar close to the point. All light reaching that point will therefore come from directions on a

(27)

hemisphere above the point, i.e. a sphere around the point split in half by its tangent plane. One may thus get all the light contributing to a surface point by integrating in all directions of the hemisphere above it (figure 4.2). To measure how much the surface point sees of another object we calculate the objects solid angle with respect to the surface point, but we only need to consider those directions that lie on the hemisphere above the surface. The directions on the hemisphere below the surface are not seen. Light does not travel from within an object to its surface.

That is if we assume the objects to be opaque, which we will do for all of this text.

4.1.3 Radiant Power

Radiant power Φ is the power of radiation per unit time W = J s−1. It can be used to measure the radiation coming to a surface or leaving a surface, e.g. a lamp.

4.1.4 Irradiance

Irradiance E is the incident radiant power on a surface per unit surface area, i.e.

incoming light.

E(¯x) = dain W m−2

To get the total incident radiant power Φin for a surface A we can integrate the irradiance E over its area:

Φin=R

A in

da da =R

A

Eda

4.1.5 Radiosity

Radiosity B is the exitant ( outgoing) radiant power on a surface per unit surface area. Sometimes called radiant exitance (figure 4.3). The word radiosity may thus refer to two things: the physical quantity of light power per area leaving a surface, and a finite element method used for calculating the former quantity for all surfaces of a scene.

B(¯x) = daout W m−2

To get the radiant power of light leaving the surface we integrate the radiosity over its area:

Φout=R

A out

da da =R

A

Bda

(28)

Figure 4.3. Radiosity is the power of light leaving a surface per unit surface area.

The main physical quantity used in the radiosity algorithm is thus itself called radiosity (B) and stands for the power of light leaving a surface at a given point, per unit area on the surface.

4.1.6 Radiance

Although radiosity and irradiance are the main physical quantities used in the radiosity algorithm, one also needs to deal with another more complicated quantity when the algorithm is to be derived. This quantity is called radiance (L) and is defined as the amount of energy traveling at some point in a specified direction, per unit time, per unit area perpendicular to the direction of travel, per unit solid angle.

L(¯x, ˆn) = dad2Φ

The definition may seem somewhat complicated. The meaning of it is to have a quantity which is like radiosity, but whereas radiosity is the total light leaving a surface point over all angles, radiance is for a specific angle. One may therefore get the radiosity by integrating the radiance over all angles as will be shown later.

Radiance is thus a function of position and direction. Every point in space have a unique radiance in every direction. If position is described by the vector ¯x and direction by the vector ˆn, radiance can be written as L(¯x, ˆn).

Whereas radiosity is generally linked to a surface this is not the case for radiance.

One may speak of the radiance coming from a specific direction to a point in the middle of air. Thus the point does not have to be on a surface but the quantity is still to be taken per area. This area is to be thought of as the area of a virtual surface placed at the point and with a normal that points in the direction in which the radiance is to be evaluated. See figure 4.4.

When the radiance of a surface point in a certain direction ˆn is considered, the surfaces normal ˆna does not generally point in the same direction. The relation

(29)

n n

da da

a

Figure 4.4. Radiance

between the infinitesimal area element of the surface da and that of the virtual surface damay be written:

da= |ˆn · ˆna| da

This allows us to deal directly with the real surfaces instead of the virtual ones.

L(¯x, ˆn) = dad2Φ = daˆnd2Φ

a·ˆndω = ¯d2Φ

da· ¯

where ¯dω = dωˆn and daˆna= ¯da

Here we do not take the absolute value of the scalar product. This results in radiance being signed as L(¯x, ˆn) = −L(¯x, −ˆn). If some positive value of radiance travels in one direction, it can just as well be seen as the same but negative value traveling in the opposite direction.

4.1.7 Radiance to Radiosity

Consider a surface point ¯x with normal ˆna. The relation between L(¯x, ˆn), the radiance at the point in various directions, and incident E(¯x) and exitant B(¯x) radiant power per surface area may be expressed as an integral over all directions n of the surface points hemisphere Ω. We integrate over all solid angles seen fromˆ the point on the surface. Let dω be an infinitesimal solid angle and let ˆn be the direction of that solid angle. Let ¯dω = dωˆn.

B(¯x) = da radiosity, i.e. the exitant radiant power per unit surface.

Loutx, ˆn) = dadω ˆd2Φn·ˆn

a outgoing radiance in direction ˆn.

Combining the above relations give:

Loutx, ˆn) = dadω ˆd2Φn·ˆn

a = d

da

dω ˆn·ˆna = dω ˆdBn·ˆn

a

dB(¯x) = Loutx, ˆn)ˆna· ˆndω = Loutx, ˆn)ˆna· ¯dω

Integrating over all directions ˆn of the surface points hemisphere Ω gives:

(30)

Figure 4.5. When calculating the light that comes to or leaves a surface point we have to integrate in all directions of its hemisphere.

B(¯x) = Z

Loutx, ˆn)ˆna· ¯dω (4.2)

where dω is the infinitesimal solid angle in direction ˆn.

In the same way we get the relation between the irradiance and the incoming radi- ance:

E(¯x) = Z

Linx, ˆn)ˆna· ¯dω (4.3)

Note the dependency of ˆna · ˆn. This is due to L being calculated as per area perpendicular to the direction. E and B on the other hand is calculated as per surface area. Light that comes from the same direction as the surface normal will be more important than light coming from the side. Light that comes from the side and “covers” a certain area perpendicular to the “ray” direction, will cover a much larger surface area when hitting the surface. The light will therefore be smeared out over a larger area than light coming from the direction of the surfaces normal.

The factor ˆna· ˆn can be further motivated if light is seen as a beam of particles, i.e.

photons. Consider a uniform beam consisting of particles moving with the same velocity. If the stream hits a surface, the more straight on the beam hits the surface the more particles will hit the surface per surface area per unit time. If you have a bucket and it is raining, the bucket will be filled faster if it is raining straight from above than from the side.

4.1.8 Conservation of Radiance Along a Ray

It is of great importance that radiance is per solid angle. This results in radiance of a certain direction being conserved when moving in that direction:

(31)

d

d b

n n

a

n

a

n

Figure 4.6. Radiance projection factor. The relation between the area d perpendic- ular to the direction ˆn and the surface area b can be described as bˆna· ˆn = d

L(¯x, ˆn) = L(¯x + tˆn, ˆn) (4.4) where t describes how far one moves in direction ˆn.

This assumes that there is no participating media affecting the propagation of light, like fog. The light (per solid angle) leaving a point in one direction will be the same as the light (per solid angle) arriving in that direction a bit farther away, if no discreet surface is in the way. 4.4 may also be expressed as:

Loutx, ˆnx→y) = Liny, ˆny→x) (4.5) This result further explains why radiance is such a suitable quantity to work with when dealing with propagation of light. In the derivation of the Radiosity Algorithm this result will be used to relate the light leaving a surface with the light arriving at another.

Proof of 4.4/4.5: Consider two surface elements numbered 1 and 2 located at ¯r1

and ¯r2 (figure 4.7). Let the first surface element radiate light to the second. The radiance emitted from from the first point in the direction of the second surface element may be written:

Loutr1, ˆr1→2) = d2Φ1,out da1¯ 1→2· ˆn1

(4.6)

where ¯1→2 = ˆr1→21→2 and dω1→2 denote the solid angle of da2 as seen from the first point. ˆr1→2 is the direction from the first point to the second. Using the definition of the solid angle 4.1 we have:

(32)

Figure 4.7. Radiance invariance. The radiance leaving a point in one direction is the same radiance that arrives further away in that direction, if no object is in the way and if there is no participating media like fog or water.

1→2 = |ˆr1→2· ˆn2| da2

r2 (4.7)

where r is the distance between the points.

Using equation 4.6 and 4.7 the differential radiant power emitted from da1 to da2

may be written :

d2Φ1,out= Loutr1, ˆr1→2)da1¯ 1→2· ˆn1

d2Φ1,out= Loutr1, ˆr1→2)da1

|ˆr1→2· ˆn2| da2

r2 ˆr1→2· ˆn1 (4.8) In the same way we can write the radiance coming from da1 to the second point as:

Linr2, ˆr2→1) = d2Φ2,in

da2¯2→1·ˆn2

and the solid angle of da1as seen from the second point:

2→1= |ˆr2→1· ˆn1| da1 r2 leading to:

d2Φ2,in= Linr2, ˆr2→1)da2¯ 2→1· ˆn2

d2Φ2,in= Linr2, ˆr2→1)da2

|ˆr2→1· ˆn1| da1

r2 ¯r2→1· ˆn2 (4.9) These expressions of radiant power may be simplified further by noting parallel vectors:

(33)

rˆ2→1 = −ˆr1→2

|ˆr1→2· ˆn2| = |−ˆr2→1· ˆn2| = |ˆr2→1· ˆn2|

|ˆr2→1· ˆn1| = |−ˆr1→2· ˆn1| = |ˆr1→2· ˆn1| using this in 4.8 and 4.9 gives:

d2Φ1,out= Loutr1, ˆr1→2)da1rˆ2→1· ˆn2da2

r2 ˆr1→2· ˆn1

d2Φ1,out= Loutr1, ˆr1→2)rˆ1→2· ˆn1rˆ2→1· ˆn2da1da2

r2 (4.10)

d2Φ2,in= Linr2, ˆr2→1)da2rˆ1→2· ˆn1da1

r2 ¯r2→1· ˆn2

d2Φ2,in= Linr2, ˆr2→1)rˆ1→2· ˆn1r¯2→1· ˆn2da1da2

r2 (4.11)

If we assume that the light does not propagate in participating media, like fog or water, and that there is no surface in between, then energy will not be absorbed on its way between the surfaces. The radiant power sent from the da1 to da2 will then be the radiant power received by da2:

d2Φ1,out = d2Φ2,in

Looking at equation 4.10 and 4.11 we see that this also leads to the radiance being conserved:

Loutr1, ˆr1→2r1→2· ˆn1rˆ2→1· ˆn2da1da2

r2 = Linr2, ˆr2→1)rˆ1→2· ˆn1r¯2→1· ˆn2da1da2

r2 Loutr1, ˆr1→2) = Linr2, ˆr2→1)

(34)

from. They have no “moving” high lights/reflections at all. This assumption may be expressed as the outgoing radiance being only a function of position and not direction:

Loutx, ˆn) = Loutx)

This is the key characteristic of the Classical Radiosity algorithm.

This simplifying assumption leads to further simplifications of equation 4.2:

B(¯x) =R

Loutx)ˆnx¯· ¯dω = Loutx)R

ˆnx¯· ¯dω

The integral R

ˆnx¯· ¯dω = R

ˆnx¯· ˆndω may be seen as a projection of the hemisphere surrounding the point to the points tangent plane which has normal ˆn¯x. When the hemisphere is projected to the tangent plane it becomes an area with the unit circle S1 as contour. The integral therefore just becomes the area of the unit circle:

dω = ˆ¯ ndω R

nˆ¯x· ˆndω =R

nˆx¯· ¯dω =R

s1

da= π

B(¯x) = πLoutx) (4.12)

Thus when assuming all surfaces to be ideal diffuse there is an easy relation between radiance, which is per solid angle, and radiant power per surface area which is the integral over all solid angles. Since an ideal diffuse surface point looks the same no matter what direction it is viewed from, one does not have to deal with its radiance in every possible direction.

The surface points radiosity is enough to tell how the point will look. This is the key characteristic of the Classical Radiosity algorithm. This greatly reduces the number of variables that needs to be calculated.

(35)

4.3 Diffuse Rendering Equation

This section will derive the Radiosity Equation. It is the central equation of the Radiosity algorithm. It describes how the radiosity of every surface point depends on the radiosity of all other surface points. In other words it describes how the final color of all parts of all surfaces in the scene depend on each other. If this equation is solved the complete global illumination of the scene is obtained.

We will start by deriving an equation that deals with radiances and then move on to an equation that just uses radiosities. We will also start by considering the scene as being continuous and consisting of infinite many surface points leading to integral equations. To be able to solve these equations we then discretize all surfaces of the scene into a finite number of small patches, in the spirit of the Finite Element Method. Each patch is then considered to have constant radiosity (in space that is, not in time). We then get an equation system describing a finite number of unknowns, the radiosities of every patch. Various methods of solving this system is later described in section 6, 8, 10 and 13.

4.3.1 Hemisphere Formulation

A surface can not reflect more light than what is incident upon it, due to the conservation of energy. The surface may however not reflect all the light that it receives. Some of the light may be absorbed and turned into heat, which may be emitted as heat radiation. This radiation is however not visible under normal conditions and we therefore do not wish to model the heat transfer, although it was in this field that the radiosity algorithm originally was developed. For our purposes we are only interested in the fraction of reflected light Br over received light E which we may denote ρ:

ρ(¯r) = BE(¯rr)r)

ρ(¯r) is a parameter that may vary with the material. It is called diffuse reflectance, reflectivity or albedo. Since we are modeling colors as three discrete channels of red, green and blue, a material will have have three generally different ρ:s corresponding to the different colors. Due to the conservation of energy we have that:

0 ≤ ρ(¯r) ≤ 1

Following the definition of ρ and using equation 4.3 we may write:

Brr) = ρ(¯x)E(¯r) = ρ(¯r)R

Linr, ˆn)ˆn¯r· ¯dω

The total exitant radiant power per unit surface is the sum of the light emitted by the surface itself Beand the light reflected Br:

(36)

Where we integrate the incoming radiance in all directions ˆn over the hemisphere Ω of the surface point ¯r. dω is the infinitesimal solid angle and ¯dω = ˆndω.

This is the rendering equation for diffuse surfaces. It tells how the outgoing radiance of a surface point depends on the radiance emitted by the surface itself Ler), and the incoming radiance Linr, ˆn) from all directions ˆn.

4.3.2 Area Formulation

According to the previous passage we have:

Loutr) = Ler) +ρ(¯πr)R

Linr, ˆn)ˆnr¯· ¯dω

We can calculate the outgoing radiance due to reflection by integrating all incoming radiance over the hemisphere Ω surrounding the surface point ¯r. Light coming to the surface point from a certain direction originally comes from another surface in that direction. Thus, just as we might account for all incoming radiance by integrating over all visible directions, i.e. the surface points hemisphere, we might just as well integrate directly over all visible surfaces. Light coming to a surface point comes from all other surface points that are visible by the former.

The solid angle subtended by an infinitesimal area is according to equation 4.1:

dω = ˆr · ˆnada

r2 = r · ¯ˆ da r2 =

r · ¯¯ da

r3

Let A be the set of all surfaces in the scene. Let V ( ¯r1, ¯r2) be a function that is 1 if the points ¯r1 and ¯r2 are visible to each other and 0 if they are not. One may then integrate over all visible surfaces by integrating over all surfaces A and having V ( ¯r1, ¯r2) in the integrand.

Note that according to equation 4.4 the radiance coming to ¯r in direction ˆn, Linr, ˆn), will be the same as the radiance leaving the nearest surface point in that direction Lout( ¯r2), which will not depend on any direction since we are assuming all surfaces to be diffuse:

Lout( ¯xr) = Ler) +ρ(¯πr)R

Linr, ˆn)ˆnr¯· ¯dω

(37)

y

y y

x

r

Figure 4.8. When describing the light coming to a surface point we integrate over all other surfaces to account for their contribution.

Loutr) = Ler) + ρ(¯r) R

¯y∈A

−Louty)V (¯r, ¯y)ˆnx¯· ˆrˆr · ˆny¯

πr2 da

where ¯r = ¯y − ¯x is the distance between the surfaces points.

using 4.12 we have

B(¯x) = πLoutx) = πLemissionx) + πρ(¯x) R

y∈A¯

−Louty)V (¯x, ¯y)ˆnx¯· ˆrˆr · ˆny¯

πr2 da

B(¯y) = πLouty) B(¯x) = Bex) + ρ(¯x) R

y∈A¯

−B(¯y)V (¯x, ¯y)ˆn¯x· ˆrˆr · ˆny¯

πr2 da

Let F (¯x, ¯y) = −nˆx¯· ˆrˆr · ˆny¯

πr2 V (¯x, ¯y) = −nˆ¯x· ¯r¯r · ˆny¯

πr4 V (¯x, ¯y) = cos α cos β

πr2 V (¯x, ¯y) F (¯x, ¯y) only depends on the geometry between the patches. It tells how the incident radiant power per surface area of ¯x depends on the exitant radiant power per surface area of ¯y.

B(¯x) = Bex) + ρ(¯x) Z

¯y∈A

B(¯y)F (¯x, ¯y)da (4.13)

We now have the area formulation of the diffuse rendering equation. This integral equation describes how the radiosity of a surface point B(¯x) depends on the light emitted by the surface itself Bex) and light coming from other surface points getting reflected. To account for the contribution from the other surfaces we integrate ¯y over all of them A, see figure 4.8. The function V (¯x, ¯y) in F (¯x, ¯y) makes sure that only surface points that are visible from ¯x contribute directly.

(38)

emitted light in the scene is constant and if all surfaces and their properties are constant, a stationary state will be reached, pretty fast considering the speed of light.

In this state, photons are emitted continuously from the light source and bounced around the scene until eventually being absorbed. The photons will however behave the same (in average) and the illumination of the scene will be static.

4.3.3 Discreet Area Formulation - Radiosity Equation

The diffuse rendering equation [4.13] is an equation system for infinite many surface points. To find a numerical solution we can approximate the scene as consisting of a finite number of small surfaces with constant properties like the radiosity B and the albedo ρ. These small surfaces are called patches. This procedure is a so-called finite element method. Adjusting equation 4.13 to explicitly be taken over each patch i in turn we get:

B(¯x) = Bex) + ρ(¯x)X

i

Z

y∈A¯ i

B(¯y)F (¯x, ¯y)dai (4.14)

Let Bi be the radiosity of patch i:

Bi = A1

i

R

x∈A¯ i

B(¯x)dai

Using equation 4.14 leads to:

Bi = A1

i

R

x∈A¯ i

Bex) + ρ(¯x)P

j

R

y∈A¯ j

B(¯y)F (¯x, ¯y)daj

! dai

Bi = A1

i

R

x∈A¯ i

Bex)dai+A1

i

R

x∈A¯ i

ρ(¯x)P

j

R

y∈A¯ j

B(¯y)F (¯x, ¯y)dajdai

Assuming ρ and B are constant over each patch:

Bi = A1

i

R

x∈A¯ i

Bex)dai+ ρiA1

i

R

¯x∈Ai

P

j

Bj R

y∈A¯ j

F (¯x, ¯y)dajdai

Taking the sum before integrating:

(39)

Bi = A1

i

R

x∈A¯ i

Bex)dai+ ρiP

j

BjA1

i

R

x∈A¯ i

R

y∈A¯ j

F (¯x, ¯y)dajdai

Let Bi,e= A1

i

R

¯x∈Ai

Bex)dai

Let Fij = A1

i

R

x∈A¯ i

R

y∈A¯ j

F (¯x, ¯y)dajdai = A1

i

R

x∈A¯ i

R

y∈A¯ j

−nˆx¯· ˆrˆr · ˆny¯

πr2 V (¯x, ¯y)dajdai

This gives us the discreet diffuse rendering equation, which is sometimes just called the radiosity equation.

Bi = Bi,e+ ρiX

j

FijBj (4.15)

The radiosity linear equation system tells that each patch’s radiosity Bi is the sum of the radiosity emitted directly by the patch Bi,eand the reflection of light that comes from every other patch that is visible to patch i. The emission Bi,e is the light that is “created” at the patch, and is thus only non-zero for surfaces that are light sources.

The reflected part depends on ρi which is the fraction of reflected light over total incident light for the patch. 0 ≤ ρi < 1.

Radiosity is thus a finite element method and its first step is to divide all surfaces in discreet small parts, so called patches. In this paper all surfaces are considered to be built up by triangular surfaces and a patch is accordingly a small triangular surface.

(Using a more theoretical terminology one may say that the surfaces are assumed to be described by a finite set of discreet basis functions. Each patch being a basis function with constant properties. One could also use other basis functions like Wavelets or Fourier-waves defined on each surface. This was however not looked into deeper in this thesis.)

References

Related documents

In regard to the first question, it was concluded that the subjective autonomy modeled within the museum space in isolation, lacks the capacity to address

The evaluation is done from two perspectives: render-time, based on scalability and handling of dynamic lighting; and visual quality, tested by using the perceptual quality

Part of the Flexor muscle group, the Pronator Teres is the only one of the four that does not attach somewhere near the hand. Its origins are at the end of the humerus and the start

Keywords: radiosity, hierarchical radiosity global illumination, light mapping, face cluster radiosity, volume cluster radiosity, texture

This project investigated the bacteria in water entering and leaving the slow sand filters at Ringsjö Water Works using flow cytometry.. The purpose was to explore the possibility

Department of Computer and Information Science Linköpings universitet. SE-581 83 Linköping

A RTOS using Xenomai's cobalt core or the PREEMPT_RT patch can be implemented on the CL-SOM-iMX7 using the i.MX7D with the i.MX vendor kernel. The I-Pipe patch for the cobalt

A protocol has been developed in Dynamo in order to upload the parameters’ values inside the Revit model of the building every time new data is inserted through the online form.