Graphics Programs Reference
In-Depth Information
Lighting Equation in Vertex Shader
To implement this lighting equation using a shader program :
▪ Inside the vertex shader, store the current vertex (say, in a variable
vertex of type vec4 ).
▪ Recall that you pass data (vertex FloatBuffer ) to this
variable by calling the ES 2.0 function glVertexAt-
tribPointer .
▪ Next, store the normal corresponding to the current vertex and
transform this normal using the MV matrix (specifically, the
upper-left 3x3 portion of the MV matrix) of the corresponding ob-
ject. This matrix, which is used to transform the normal, is called
the normal matrix.
Note As Chapter 4 explains, the Perl (mesh) parser calculates the
normalized average of adjacent mesh-normals for every vertex, so
as to obtain the normals (that is, normal vectors) along them.
▪ Normals (that is, normal vectors) transform differently than ver-
tices. The normal matrix should be the inverse-transpose of the
upper-left 3x3 portion of the MV matrix corresponding to the ob-
ject. However, as long as the MV matrix does not include any
non-uniform scalings, then you can use the upper-left 3x3 portion
of the MV matrix to transform the normals. Please note that, in
non-uniform scaling, an object is enlarged or shrunk by a factor
that is not the same along all axes.
Note To look deeper into the concepts on non-uniform scaling
of normals, refer the following URL: ht-
tp://www.lighthouse3d.com/tutorials/glsl-tu-
torial/the-normal-matrix/ .
Search WWH ::




Custom Search