Graphics Reference
In-Depth Information
rotated to show that the model coordinates stay with the object's geometry,
but the eye coordinates stay fixed relative to the viewing space. That is, on the
left, the stripes are parallel to the YZ plane of the model coordinates, and on
the right, the stripes are parallel to the YZ plane of the rotated (eye) coordinate
space.
Below is the vertex shader for Figure 7.3, with a Boolean switch to choose
whether you want to send the eye-space or model-space coordinates on to
the fragment shader. The lighting computation in this shader is very simple,
merely handling the diffuse light intensity that would be part of a full light-
ing model, as we will discuss later in this chapter. In Chapter 8, we will show
a simple fragment shader that handles the coordinates that this vertex shader
develops.
uniform bool uUseModelCoords;
out vec4 vColor;
out float vX, vY, vZ;
out float vLightIntensity;
void
main( )
{
vec3 TransNorm = normalize( uNormalMatrix * aNormal );
vec3 LightPos = vec3( 0., 0., 10. );
vec3 ECposition = ( uModelViewMatrix * aVertex ).xyz;
vLightIntensity = dot(normalize(LightPos - ECposition),
TransNorm);
vLightIntensity = abs( vLightIntensity );
vColor = aColor;
vec3 MCposition = aVertex.xyz;
if( uUseModelCoords )
{
vX = MCposition.x;
vY = MCposition.y;
vZ = MCposition.z;
}
else
{
vX = ECposition.x;
vY = ECposition.y;
vZ = ECposition.z;
}
gl_Position = uModelViewProjectionMatrix * aVertex;
}
Search WWH ::




Custom Search