Silicon Graphics

[Prev] [TOC] [Next]



(-) OpenGL Programming Guide
(-) Chapter 6Lighting
(-) The Mathematics of Lighting

Contributions from Light Sources

Each light source may contribute to a vertex's color, and these contributions are added together. The equation for computing each light source's contribution is as follows:

contribution = attenuation factor * spotlight effect *

(ambient term + diffuse term + specular term)

Attenuation Factor

The attenuation factor was described in "Position and Attenuation" :

attenuation factor =

[IMAGE]

where

d = distance between the light's position and the vertex

kc = GL_CONSTANT_ATTENUATION

kl = GL_LINEAR_ATTENUATION

kq = GL_QUADRATIC_ATTENUATION

If the light is a directional one, the attenuation factor is 1.

Spotlight Effect

The spotlight effect evaluates to one of three possible values, depending on whether the light is actually a spotlight and whether the vertex lies inside or outside the cone of illumination produced by the spotlight:

To determine whether a particular vertex lies within the cone of illumination, OpenGL evaluates (max { v x d , 0 } ) where v and d are as defined above. If this value is less than the cosine of the spotlight's cutoff angle (GL_SPOT_CUTOFF), then the vertex lies outside the cone; otherwise, it's inside the cone.

Ambient Term

The ambient term is simply the ambient color of the light scaled by the ambient material property:

ambientlight *ambientmaterial

Diffuse Term

The diffuse term needs to take into account whether light falls directly on the vertex, the diffuse color of the light, and the diffuse material property:

(max { l · n , 0 } ) * diffuselight * diffusematerial where:

l = (lx, ly, lz) is the unit vector that points from the vertex to the light position (GL_POSITION).

n = (nx, ny, nz) is the unit normal vector at the vertex.

Specular Term

The specular term also depends on whether light falls directly on the vertex. If l · n is less than or equal to zero, there is no specular component at the vertex. (If it's less than zero, the light is on the wrong side of the surface.) If there's a specular component, it depends on the following:

Using these definitions, here's how OpenGL calculates the specular term:

(max { s x n , 0} )shininess * specularlight * specularmaterial

However, if 1 x n = 0, the specular term is 0.


[Prev] [TOC] [Next]

OpenGL Programming Guide


Maintained by Maintainer: Send e-mail to .htm">name@address.