Graphics Reference
In-Depth Information
Specular light contributes to the lighting as a product of the specular
light itself
M and a
power (the “shininess” coefficient SH ) of the cosine of the angle Φ between the
eye vector and the light reflection vector, ( R E ) SH  :
S = L S * M S * ( R E ) SH .
Then the total lighting at the point is the sum of these:
A + D + S = L A * M A + L D * M D * ( L N ) + L S * M S * ( R E ) SH .
L
,
the specular light color of the material being lighted
,
The reflection vector R is calculated by R = 2( N L ) N L . Details on how
these individual formulas are derived may be found in any introductory graph-
ics text, such as [14]. Also, GLSL has a built-in function called reflect( ) ,
which will do this for you.
This model can also take into account atenuation, or the reduction in
light intensity with distance. OpenGL models this with three factors: a con-
stant atenuation A C  , a linear atenuation A L  , and a quadratic atenuation A Q . If
a point is at a distance D from a light, the overall atenuation A is calculated as
1
A AADAD
C
=
2 .
+
+
L
Q
The distance can be calculated from the light and vertex positions in eye
space, and this value of A then multiplies the diffuse and specular terms above.
In the ADS lighting function in the next section, we use the reflected-light
formulation because we have access to the reflection for each pixel, using the
GLSL function reflect( ) to compute the reflection vector. However, fixed-
function OpenGL uses the half-angle formulation for specular light because it
is easier to compute for each vertex.
The ADS Lighting Model Function
Below is a function that computes the color at a vertex based on the ADS light-
ing model with standard light and material definitions. It is intended for use
with glman , so it uses stubs for the values it would get from another source.
These stubbed values would come from system uniform variables, as noted in
the function's comments.
You can use this function in a vertex shader if you are computing the
color at each vertex, as you would if you were planning to interpolate the color
across the graphics primitive, as in smooth shading, or you can use it in a frag-
Search WWH ::




Custom Search