Game Development Reference
In-Depth Information
2
3
2
3
n
n
4
s j max ( n h j ,0) m gls
5
4
5
=
m spec +
s j max ( n l j ,0)
m diff
j=1
j=1
+ g amb
m amb + m emis .
Finally, we make the very reasonable assumption that m amb = m diff :
2
3
n
A version of the standard
lighting equation more
suitable for vertex-level
lighting computations
s j max ( n h j ,0) m gls
4
5
c lit =
m spec
j=1
2
4
3
5
(10.15)
n
+
g amb +
s j max ( n l j ,0)
m diff
j=1
+ m emis .
With the lighting equation in the format of Equation (10.15), we can
see how to use interpolated lighting values computed at the vertex level. At
each vertex, we will compute two values: v spec contains the specular portion
of Equation (10.15) and v diff contains the ambient and diffuse terms:
n
n
s j max ( n h j ,0) m gls
v spec =
v diff = g amb +
s j max ( n l j ,0).
Vertex-level diffuse and
specular lighting values
j=1
j=1
Each of these values is computed per vertex and interpolated across the
face of the triangle. Then, per pixel, the light contributions are multiplied
by the corresponding material colors and summed:
Shading pixels using
interpolated lighting
values
c lit = v spec
m spec + v diff
m diff + m emis .
As mentioned earlier, m spec is sometimes a constant color, in which case
we could move this multiplication into the vertex shader. But it also can
come from a specular map.
What coordinate space should be used for lighting computations? We
could perform the lighting computations in world space. Vertex positions
and normals would be transformed into world space, lighting would be
performed, and then the vertex positions would be transformed into clip
space. Or we may transform the lights into modeling space, and perform
lighting computations in modeling space. Since there are usually fewer
lights than there are vertices, this results in fewer overall vector-matrix
multiplications. A third possibility is to perform the lighting computations
in camera space.
Search WWH ::




Custom Search