O'Reilly logo

Graphics Shaders, 2nd Edition by Steve Cunningham, Mike Bailey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

139
In xed-function OpenGL, the vertex processing in the graphics pipeline is
responsible for taking the model-space geometry you dene, along with what-
ever color, lighting, materials, shading, and texture information you specify,
and creating a set of vertices in clip space that have color, depth, normal,
and texture associated with each. The role of the vertex shader is shown in
Figure 7.1. The vertex shader replaces much of the xed-function vertex pro-
cessing, and possibly changes the vertex coordinates as well. It also sets up
the shader environment for any further vertex processing by tessellation and
geometry shaders and for the rasterization and fragment shader processing.
In this chapter, we will discuss the vertex shader from a functional
approach: what it does, what its inputs are, what its outputs are, and what
kind of operations it can perform. We will also see several examples of vertex
shaders that carry out many of these shaders’ dierent operations.
7
Vertex Shaders
140
7. Vertex Shaders
Vertex Shaders in the Graphics Pipeline
As we consider in detail how the
vertex shader works in the graph-
ics pipeline, we need to look at the
inputs to a shader and the outputs
from a shader, as well as the kinds
of processing that can go between
the input and the output.
In the discussions below, we
will often refer to aspects of the
GLSL shader languages that were
presented in Chapter 5, because
vertex processors deal with ari-
bute variables, uniform variables,
and variables that are passed to
other shaders for their work. If you
are working through this book in
chapter order, this material should
be fresh, but if you are picking it up
bit by bit, you should at least skim
Chapter 5 to understand the basic
ideas of GLSL variables.
Input to Vertex Shaders
Vertex shaders take the inputs that would ordinarily go to the vertex process-
ing stage of the graphics pipeline, along with other data that the application
might want to send to the shaders. This lets the vertex shader replace key parts
of the standard vertex processing. Vertex shaders can take aribute and uni-
form variables as inputs, and produce other variables as outputs. Both ari-
bute and uniform variables are treated as read-only variables by vertex shad-
ers. (Vertex shader out variables are treated as write-only variables destined
for the next stage in the pipeline.)
Aribute variables can take on a dierent value for each vertex in your
model and are considered to be read-only to the vertex shader. Some of the
aribute variables are built-in to GLSL, such as vertex coordinates, vertex
color, vertex normal, and vertex texture coordinates.
Figure 7.1. The place of vertex shaders in the pipeline.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required