Radiosity 101: An Introduction to 3-d Graphics Programming

By Ming-Yee Iu

Note: Graphics is a very broad topic which takes much longer than a short overview to understand. This document is meant only to provide you with enough knowledge to implement a radiosity solver. If this material interests you, I encourage you to explore this area in more detail as it is a very rich and fulfilling area.

Note 2: In order to gain the greatest understanding of this material, it is suggested that you know

Note 3: The person who wrote this material already forgot all his OAC algebra and geometry as soon as the exam was over, has the drawing skills of a two year old, and thinks refraction is a mathematical term, so don't feel intimidated by the above list.

Introduction

Computer graphics is all about deception and trickery. The goal of computer graphics is to fool people into seeing something that isn't there. The image on a monitor is just a series of coloured dots, but if those dots are positioned carefully, a breathtaking picture can be formed.


[A bunch of dots]


[From far enough away, these dots make up the Mona Lisa (picture stolen from Stanford somewhere)]

In 3-d computer graphics, the nature of the deception is different. Enough physics is known about the nature of light and matter that is possible to create very accurate representations of the physical world on the computer. Unfortunately, the amount of memory and computational power required to do this exceeds the capabilities of any computer available today. Therefore, the deception in 3-d computer graphics is to create an image that looks real but only using an acceptable amount of computing power and storage. You might have to make various approximations of the equations involved or even leave out important details to make the calculations easier. The trick is to find out which trade-offs result in the best looking images but can be produced in an acceptable amount of time. For example, most computer games don't model shadows accurately in order to speed up the game, yet most people don't notice this shortcoming.


[Series of buildings without shadows]

[Series of buildings with shadows]

Representation of 3-d Scenes

In computer graphics, the basic "unit" for modeling the physical world is the polygon. A polygon is simply a flat multi-sided object.

[Polygon]

Now a polygon by itself is a pretty boring thing: it's just a flat surface after all. But if you put a lot of them together, you can make more complex things like curves, spheres, or Christmas trees.


[A pine tree, a curve, and a sphere, modeled using polygons]

Now, it is possible to actually store curves and spheres in a computer as curves and spheres, but polygons are generally used instead because they're much easier to do calculations with, and much easier to represent. Calculations with curved surfaces involve many special cases and exceptions whereas polygons don't. And polygons, in their simplest representation, can simply be stored as a series of vertices.


[Polygon with its vertices labeled]

In fact, most graphics programs use only three and four sided polygons. Three sided polygons are used because with only three edges, it's impossible to make "difficult" shapes with lines that cross or with holes inside of them. Also, with three sided polygons, all three vertices are guaranteed to lie on the same plane; with more than three vertices, it's possible not to have all the vertices lined up properly.


["Difficult" polygons that are possible when more than three vertices are allowed]

Four-sided polygons are often used because many objects in real-life can be more easily modeled using four-sided polygons. For example, the sides of a building can be modeled as giant rectangles. Also, it is easier to "map" images onto polygons if they're four sided. (Mapping images onto polygons is a common technique in computer graphics. For example, to make an object look wooden, an image of wood is mapped onto the surface of the polygons that make up that object.)

Although it is possible to do 3-d computer graphics using spheres, curves, and other shapes, polygons make everything so much easier to work with that you should consider the polygon to be your friend.


[The polygon, you friend]

Disappearing, Reappearing Polygons

One interesting thing about the way polygons are represented in computer programs is that they are usually one-sided. What this means is that if you look at a polygon from the wrong angle, it will disappear.


[Visible polygon]


[Invisible polygon]

Computer polygons have a "facing" or "direction." This "facing" is represented on the above diagrams using little arrows. The arrow indicates which side of the polygon is the front face and which side is the back face. When the arrow points towards you, you are looking at the front face of the polygon. When the arrow is pointing away from you, you are looking at the back face of the polygon. A polygon viewed from its front face is visible while a polygon viewed from its back is invisible (i.e. the computer doesn't bother drawing the polygon). This is useful for modeling solid shapes. A cube can be represented as six polygons all "pointing" outwards. When the cube is drawn on screen, some of the polygons will point away from the viewer. This means that they are being viewed from the wrong side and will "disappear." This process is known as back face culling, and it makes the calculations a lot easier because then the computer won't waste time doing calculations for polygons that can't be seen.


[Cube with the "directions" of its polygons labeled]

The "facing" of a polygon is equivalent to its surface normal. I've forgotten how to calculation surface normals, but it should be in some textbook somewhere.

Another interesting thing about one-sided polygons is that they can be used to make two-sided polygons. By putting two one-sided polygons in the same position but facing different directions, a two-sided polygon can be made. This two-sided polygon can be used to model really thin walls and other similarly thin objects. And if each of the one-sided polygons are coloured differently, then both sides of the wall can have different colours--just like a real wall.

The Nature of Light

Now if you remember from grade 10 science, the way we see things is that light comes from a source, bounces off objects, and then enters our eyes (traveling in nice straight lines the whole time, of course). We see an object when light bouncing off of that object enters our eyes.


[Light bouncing around]

Shadows are just places where no light reaches.


[Light does not reach behind the wall, creating a shadow there]

Now there's actually a little twist to this. The further light travels, the less intense it becomes. This is because when light radiates from somewhere, it usually travels in all directions, so as you get farther and farther away from this source, less and less light ends up getting to you, so things aren't as bright. Essentially, things further away from a light aren't as bright


[More light hits the closer person than the farther person]


[It is brighter directly underneath the street lamp than further away]

This can all be expressed as a nice little equation shown here. Note how the intensity of light decreases the further you get away from the light source.


[Equation of light where I is the intensity of light, P is the initial power of the light, and r is the distance away from the light source]

Now the exception that proves the rule, so to say, is the sun. The sun is so far, and it is so bright, that by the time the light from the sun reaches Earth, the denominator part of the equation essentially becomes insignificant. So usually, the light of the sun is approximated as a constant value that's all coming from the same direction.


[Light from the is often approximated as always coming from the same angle and having the same intensity]

Reflection

Now when light hits a mirror, it reflects off at the same angle. This is known as specular reflection.


[Light bouncing off a mirror and hitting someone]


[In this scene, light from the light bulb bounces off the painting, hits the mirror, reflects off in a specular fashion towards our eyes. Note that light from the light bulb is also reflecting directly off of the mirror at the same time, but it is not reflected towards our eyes]

Although the concept of specular reflection is useful when dealing with mirrors, most objects, unfortunately, don't act like mirrors. Normal, non-shiny objects don't exhibit any specular reflection. Instead, they exhibit what is known as diffuse reflection. If you look very, very closely at the surface of most objects, you will find that it is very rough and uneven.


[The surface of an apple, though it appears smooth, is actually very rough when viewed closely]

When light hits this uneven surface, the surface acts like a series of mirrors all pointed in different directions; therefore, the light bounces off in many different and unpredictable directions.


[When lights hits a rough surface, it is reflected in many different directions]

This is what happens to individual light photons when working on a sub-microscopic level. For most practical computer graphics applications though, the reflection of light from a rough surface can be modeled by assuming that light hitting a rough surface is scattered in all directions by the surface. This type of reflection is known as diffuse reflection.


[Light hitting the apple is scattered equally in all directions]

More Details on Diffuse Reflection

As mentioned before, most objects exhibit diffuse reflection and only exhibit limited specular reflection, if any. The amount of light that is diffusely reflected off of an object and that enters our eyes is interpreted by our brains as the brightness or colour of that object. For example, a black table absorbs most of the light that hits it while only diffusely reflecting a little bit of that light. Some of this reflected light will enter our eyes. Since only a small amount of light from the table enters our eyes, our brain will interpret it as meaning that the table is black. A white table, on the other hand, reflects most of the light that hits it; therefore, a lot of light will reflect off the table and enter our eyes. Our brains will interpret this large amount of light as meaning that the table is white.

[possible diagram here]

Therefore, if we can calculate how much light is being reflected off of an object, we can determine its brightness. This is expressed in the equation below.

Note: From now on, when I refer to brightness, what I actually mean is colour. The explanation of the basics of radiosity so far has only deals with black and white images where things can be bright (i.e. white) or dark (i.e. black). Colour images are just a special case of black and white images though, and I'll discuss colour at the very end. I just wanted to point this out because the term brightness is sort of abstract, so if you interpret brightness to mean colour (or shades of gray or whatever), it may help you understand the material better.


[Brightness of an object depends on the amount of light hitting the object and how much of that light that the object reflects]

The percentage of light which is reflected from the surface of an object or its reflectivity is normally denoted by the Greek symbol rho. The amount of light hitting the surface can be assumed to be just the amount of light coming from the various light sources.


[The same equation as before but changed a bit]

[perhaps a diagram which demonstrates how this equation applies to a 3-d scene here]

If you remember from the discussion of the nature of light, the intensity of the light coming from a light source decreases the further away you get from the source. This must be put into the equation.


[An actual applicable equation for modeling the brightness of an object]

The above equation is actually quite a reasonable equation for determining how bright an object is. Many programs use a similar model. Most ray-tracing programs use this model (most 3-d movie effects are created using ray-tracers), and most games also use this model, if not a simpler one. You have to be careful to check if the light from a light source is blocked by another object before it hits the object you are examining, but overall the equation isn't too difficult to apply.

In order to derive this equation, we assumed that the amount of light hitting the surface of the object was just the sum of all the light coming from all the light sources. Although this produces a usable equation and good looking images, this assumption is incorrect.

[more complicated example here]

Using Radiosity to Calculate Lighting and Shadows

Now all this stuff has been pretty intuitive so far, but it finally leads up to the concept of radiosity. Consider a scene with one light source and two walls. When light hits the first wall, it is scattered in all directions. This reflected light might, in turn, hit the second wall and get scattered some more. This light might then get reflected back to the first wall, and so on.

[picture of light bouncing between two walls]

The essence of radiosity is that a scene is divided into many tiny little polygons. Light is added to the scene, and the way that light travels between all of these little polygons is modeled. And from there, the shadows and shading of the scene can be determined.

[picture of scene divided into little polygons]

[picture of little polygons being shaded]

So the first step of radiosity, is to divide a scene into lots of tiny little patches. The light coming from this little patch can be represented by this equation:

[equation]

B is the light coming from the patch. Obviously, the more light coming from a patch, the brighter it is and the lighter colour it should be when it is drawn. E is the light being emitted from the patch. Usually this is zero, but for stuff like light bulbs or fluorescent tubes that actually emit light, this would represent the amount of life given off by the patch. The rho is the patch's reflectivity which indicates how much light is reflected and how much is absorbed. Oh yeah, radiosity only handles diffuse reflection, so rho is actually a measure of diffuse reflectivity. This big summation here sums up all the light hitting the patch from other places. This should make sense: the amount of light given off by a patch is the light that it naturally emits plus all the light coming from elsewhere that are reflected off the surface. The B in the summation is the light being emitted from another patch. The ratio of As is actually a ratio of areas--if the light from a big patch hits a small patch, it'll have more effect than if the light from a small patch hits a big patch, and this ratio takes this into account. The F is called a form factor. I'll go into more detail about it later, but essentially, it scales the values of incoming light so as to take into account distance and stuff like that. One simplification which can be done to this equation depends on the relationship between form factors and area. By using this, you can eliminate the area ratio.

[equation showing how AF=AF and how it affects the equation]

Form Factor

The form factor is a measure of how much of the light coming from one patch reaches another patch. If we have two patches and consider how much light coming from one point of one of the patches reaches another point on the other patch, we get this equation.

[form factor equation for two points]

The pi, r squared term at the bottom of the expression represents how light becomes less intense the further it has to travel. The cosines are there because when a patch is rotated so that it is not parallel with the surface where light is coming from, less light falls on it. This actually isn't the most obvious thing, but hopefully you can see it in this diagram.

[diagram with row of lights and a patch]

In the diagram, there's a wall with a bunch of lights attached to it, and wall where the light is shining onto. If you look at just one of the lights, you'll notice that light rays shoot off in all directions from it, and some of them hit the other wall. If one of the walls is rotated, you'll notice that fewer light rays now hit the wall. So the cosines in the equation are used to account for this.

[less light shining on the wall]

Now the equation we have so far only takes into account light going from one point to another point. We actually want to work with light coming from an entire patch, so the obvious thing to do is to integrate over the entire patch that the light is coming from.

[form factor integrated once]

And, of course, we have to integrate again to get the average form factor of the patch which is "receiving" the light (you also have to divide by the area of the patch to get the average).

[form factor with double integrals]

In reality though, this second integral is sort of annoying, so people tend to leave that previous step out. The general reasoning behind this is that the light hitting that one patch is generally representative of how light hits all the points on the patch, so it's OK to leave out the averaging of form factors step.

[original form factor with a single integral]

So this leaves us with an equation with one integral. The equation accurately models how light from one patch hits a single point on another patch. Unfortunately, this equation is still pretty annoying because of that integral there. Fortunately, someone thought about this a lot and determined an easy way to calculate this equation. What you do is you draw a half-sphere (or hemisphere) of radius one around one of the points on the patch. Then, you project the other patch onto the sphere. You then project the result onto the base of the sphere, and divide the area of the resulting shape by the area of this circle formed at the base of the hemisphere. The act of projecting a polygon onto a hemisphere is equivalent to one of the cosines and the r squared term in the equation. Projecting that onto the base of the polygon gives you the other cosine, and dividing by the area of the circle gives you the pi.

[picture of the hemisphere projections]

And if you ignore the fact that a straight line projected onto a hemisphere results in a curved line, then the calculations become even easier because you only have to project the vertices of the patch, and then you join the new vertices after they've been projected by straight lines when you calculate the area.

How Radiosity Works

So far, we've got a bunch of equations describing how light travels between polygons, but we still don't have a method for actually calculating how bright a particular polygon is. The usual algorithm for doing this is known as progressive refinement. With progressive refinement, you start by assuming that everything in the 3-d scene you are trying to solve is completely dark except for the objects that radiate light (like light bulbs and stuff). You then list the patches in order of how much light is being radiates by them. The patches of things like light bulbs will then end up at the start of the list while everything else will end up at the end of the list.

Approximations of the Form Factor

More Info about Radiosity

(Colour, winged-edged stuff)

Displaying / Rendering These Scenes

References

[Home]


Last updated February 26, 1998.
Maintained by Ming-Yee Iu
.