Sunday, May 24, 2009

Lights

The beauty of the game is greatly influenced by how the lights are used.

Basic Light Properties
Position, Range, Attenuation, Direction
Position of the light is represented as a position vector in the world space. Range is the maximum distance from the position at which the light’s intensity is non-zero. Attenuation controls how a light's intensity decreases toward the range. It is given as a set of three constants. The direction property represents the direction in which light rays travel. It is represented using a vector.

Light Color Components
The light emitted by a light source consists of Ambient, Diffuse and Specular components.
1. Ambient light
It provides constant lighting for a scene. It lights all object vertices the same because it is not dependent on any other lighting factors such as vertex normals, light direction, light position, range, or attenuation.
2. Diffuse Light
Diffuse light comes from one direction, so it is brighter if it comes squarely down on a surface than if it barely glances off the surface. Once it hits a surface, however, it is scattered equally in all directions, so it appears equally bright, no matter where the eye is located.
3. Specular Light
Specular light tends to reflect off the surface in a preferred direction causing a bright shine that can only be seen from some angles. A shiny metal or plastic has a high specular component, and chalk or carpet has almost none.
Emissive Light
Emissive Lighting is light that is emitted by an object, not by the light source. Emissive light lights all object vertices with the color defined in the material emissive property. It is not dependent on the vertex normal or the light direction.

Types of Sources
A light source may be of type point, directional or a spotlight.
1. Point Source
Point lights have color and position within a scene. They emit light equally in all directions. A light bulb is a good example of a point light. Point lights are affected by attenuation and range. Since point sources have no single direction, for calculating lighting at vertex, the light vector is calculated by subtracting the position vector of the vertex from the point source’s position vector.
2. Directional Source
Directional lights have only color and direction, not position. They emit parallel light. This means that all light generated by directional lights travels through a scene in the same direction. Imagine a directional light as a light source at near infinite distance, such as the sun. Directional lights are not affected by attenuation or range, so the direction and color are the only factors considered when the lighting calculation is done. Because of the small number of illumination factors, these are the least computationally intensive lights to use.
3. Spotlight
Spotlights emit a cone of light, which has two parts; a bright inner cone and an outer cone. Light is brightest in the inner cone and is not present outside the outer cone, with light intensity attenuating between the two areas. This type of attenuation is known as fall off. Spotlights are affected by falloff, attenuation, and range. These factors, as well as the distance light travels to each vertex, are figured in when computing lighting effects for objects in a scene.