Graphics Reference
In-Depth Information
Going Beyond the Fixed-Function
Pipeline with Vertex Shaders
So far, we have focused on how you can use vertex shaders just to replace fixed-
function capabilities. While that may seem redundant, it may have helped you
to understand how to keep some of the kinds of graphics you want when you
move to using shaders. It may also become the only way to get your graph-
ics on devices that do not support the fixed-function pipeline in their built-in
graphics systems.
Shaders have the capability to add new functionality to the standard
fixed-function kind of graphics. We have seen that techniques such as Phong
shading, long missing from OpenGL graphics, are now possible using the
combined capabilities of vertex and fragment shaders. Similarly, the vertex
shader can be set up to take user-deined per-vertex atribute data to a vertex
shader, so that an image can be directly derived from application data.
When we discussed the inputs to the vertex shader, we noted that an
application can deine its own atribute variables for use by shaders. As we
pointed out earlier, however, only a vertex shader can read an atribute vari-
able, so one of a vertex shader's tasks is to transfer the necessary atribute val-
ues to other variables, so they can be used in whatever ways the application
has in mind. Of course, a vertex shader can modify the values in the process.
These atribute variables may also be used in the vertex shader itself. This lets
you define shaders that respond to data in different ways, a critical capability
that will be exploited when we discuss scientific visualization in a later chapter.
Vertex Modification
A vertex shader can modify the coordinates it receives. The vertex shader is
a one-vertex-in, one-vertex-out process, and it cannot create more vertices—
that's what tessellation and geometry shaders are for. The main application
of vertex shaders is to change the vertices of the primitives you already have
defined, and to set up variables such as lighting that depend on the vertices.
Some of this could take user-deined atribute or uniform variables and use
them to define the changes to be made.
Dome Geometry Example
The fixed function pipeline is limited to performing linear transformations on
vertices. A very interesting use for vertex shaders is to transform vertices in
ways that the fixed function pipeline cannot. One such application is to per-
Search WWH ::




Custom Search