Graphics Reference
In-Depth Information
putation using the normal, vertex eye coordinates, and light position, and
that it sets the required output gl_Position from the uModelViewProjection
matrix and the vertex coordinates.
uniform mat4 uModelViewMatrix;
uniform mat4 uModelViewProjectionMatrix;
uniform mat3 uNormalMatrix;
in vec4 aVertex;
in vec4 aNormal;
in vec4 aColor;
out vec4 vColor;
out vec3 vMCposition;
out float vLightIntensity;
const vec3 LIGHTPOS = vec3( 3., 5., 10. );
void main( )
{
vec3 transNorm = normalize( uNormalMatrix * aNormal );
vec3 ECposition = vec3( uModelViewMatrix * aVertex );
vLightIntensity = dot(normalize(LIGHTPOS - ECposition),
transNorm);
vLightIntensity = abs( vLightIntensity );
vColor = aColor;
vMCposition = aVertex.xyz;
gl_Position = uModelViewProjectionMatrix * aVertex;
}
The example for Figure 3.3 did not do one important thing that a vertex
shader can do, however: modify the application-supplied vertex coordinates.
As an example of geometry modification, let's start with a simple plane (rep-
resented by a 200 × 200 mesh of quads) considered as the domain of a func-
tion, and let the vertex shader apply that function. The GLIB file is essentially
the same as that for the Figure 3.3 example, except that the specified geometry
is a 200 × 200 set of quads in the XY-plane, instead of a sphere, specified like
this:
QuadXY -2. 1. 200 200
The vertex shader will apply the function
(
)
(
) =∗ +
2
2
zxy
,
03
.
sin
x
y
Search WWH ::




Custom Search