September 30, 2009

Illumination in 3D
Light enables us to see the world. In-fact, light enables us to exist on earth. Without light, there would be a dark black world. What we see is an outcome of what is received at the eye in form of light.
In 3D, we can display objects without light if we rendered them with flat colors, but we will lack the vision of depth, smooth shades and above all “realism”. From programming point of view, light is a simple “vector” with some additional characteristics. For general purpose, only a single light source is used. That means, only one light vector is used to illuminate the object surface.Before we start implementing light, we should have a little bit knowledge about rendering and shading.

Rendering is the process by which 3D objects in the scene are displayed after a lot of calculations which involve object properties and light properties.

In simple terms, rendering determines the surface color of the 3D object.

And in more simple terms, rendering calculates the color of pixel.

The program which is responsible for rendering is often called as renderer.

Shading determines the level of color intensity ranging from dark to bright.

Types of Rendering methods:

1. Scanline.
2. Ray-Tracing.
3. Radiosity.

Types of shading:

1. Flat shading.
2. Gouraud shading.
3. Phong shading.
4. Toon shading.

In rendering 3 things are involved:

1. 3D objects
2. Light
3. Camera

shadetypes

All or some of the properties listed below are used by the rendering program.
3D Object Properties

Location (x,y,z)
Color
Texture
Transparency
Reflectivity
Refractivity
Emissivity
Diffusion
Strength
Specularity

Light Properties

Location (x,y,z)
Color
Intensity
No. of photons considered
Type of light used (Ambient, Spot, Directional, Point, Area light, Volume light)

Algorithm for a simple rendering of a 3D polygonal object to achieve flat shading:

1. Get visible polygons of the object
2. Z-Sort the visible polygons
3. For each visible polygon
4.       Get the polygon normal
5.       Calculate the dot product for the polygon normal
.         and light normal
6.       Calculate flat shade color by multiplying the R,G,B
.         values of the material color with dot product
7.       For each point in polygon
8.              Set the pixel color to the calculated flat shade color
9.       Next point in polygon
10. Next polygon

Algorithm for a simple rendering of a 3D polygonal object to achieve smooth shading:

1. Get visible polygons of the object
2. Z-Sort the visible polygons
3. For each visible polygon
4.        For each point in polygon
5.               Calculate the surface normal
6.               Calculate the dot product for the surface normal
.                 and light normal
7.               Calculate the surface color of the point by multiplying
.                 the R,G,B values of the material color with dot product
8.        Next point in polygon
9. Next polygon

I have only tried to explain very briefly about implementing light in a 3D scene and as such the article is not a complete explanation of illumination model. Implementing a complete technically feasible illumination model gives the most near-realistic rendering. Illumination in 3D is a quite vast topic enough to fit into a special book. But it is really fascinating using mathematics to illuminate a 3D world using lights. And one day in the future, we may not be able to differentiate a original photograph and a 3D render by any means. I am eagerly waiting for that day’s fine morning.