Graphics Reference
In-Depth Information
Figure 3.4. A rippled surface generated by a vertex shader; still with simple color, ambient
plus diffuse lighting, and smooth shading.
to the x and y coordinates of each vertex to calculate the z -coordinate, and will
calculate the normals to each vertex by using an analytic computation, since
the derivative is known. This uses the fact that the tangent vectors are given by
taking the derivatives of z with respect to x and y :
z
x
(
)
2
2
=
203
.* .
∗ ∗
x
cos
x
+
y
,
z
y
(
)
=
203
.* .
∗ ∗
y
cos
x
2
+
y
2
.
After the vertices and normals are set up, the usual computations for eye
coordinates (ECposition) and light intensity are done. The resulting function
surface is shown in Figure 3.4.
The vertex shader for the rippled surface in Figure 3.4 is given below. The
operations for the diffuse light intensity are those for standard ambient and dif-
fuse lighting, based on the eye-space coordinates of each vertex (the ECpos vari-
able), the normal (myNorml) computed from the analytic partial derivatives,
and a fixed light position (LIGHTPOS) that would ordinarily be passed into the
shader from the application as a uniform variable. The actual display coordi-
nates gl_Position are set by multiplying by uModelViewProjectionMatrix to
apply the model, view, and projection transformations. The output of this ver-
tex shader includes two variables: the light intensity and color values defined
in the vertex shader. None of this is difficult, but it requires you to work with
your objects at a lower level than the usual OpenGL.
Search WWH ::




Custom Search