Graphics Reference
In-Depth Information
graphics pipeline. This is underscored by the fact that some graphics devices
are starting to use OpenGL ES 2.0, which omits all fixed-function operations.
In this section, we will look at some familiar functionality and develop vertex
shaders to carry out those functions. We will look at standard kinds of opera-
tions, including several kinds of lighting and shading, and will show a vertex
shader for each. In Chapter 8, we will develop fragment shaders to go with
many of these vertex shaders, so that you can see a full solution. The full solu-
tion will be included with the materials available for the topic.
Standard Vertex Processing
The vertex and primitive grouping information for a vertex shader comes
directly from the graphics application as atribute variables or as user-deined
uniform or other variables, as described above. The original vertex geometry
is in model space, so the normal and vertex position need to be set into world
space and then eye space, the built-in gl_Position variable needs to be defined,
and the light intensity and color need to be defined as new variables and made
available to later fragment shader processing. This is very straightforward, as
shown in the simple vertex shader below. This shader comes from a glman
example that defines the light position in the vertex shader, rather than taking
it as an atribute variable from the application. It also does not compute the
fragment colors itself, but sends the variables vColor and vLightIntensity to
be used to determine the pixel colors in the fragment shader, as we have seen
in earlier examples.
out vec4 vColor;
out float vLightIntensity;
void
main( )
{
const vec3 LIGHTPOS = vec3( 3., 5., 10. );
vec3 TransNorm = normalize( uNormalMatrix * aNormal );
vec3 ECposition = ( uModelViewMatrix * aVertex ).xyz;
vLightIntensity = dot(normalize(LIGHTPOS - ECposition),\
TransNorm);
vLightIntensity = abs( vLightIntensity );
vColor = aColor;
gl_Position = uModelViewProjectionMatrix * aVertex;
}
Search WWH ::




Custom Search