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

39
Fundamental Shader
Concepts
3
Shaders in the Graphics Pipeline
Let’s have another look at the graphics pipeline, but let’s break it out in a lile
dierent way than we did in the previous chapter. Let’s add into the pipe-
line the ve shaders we are considering in this book: vertex shaders, tessella-
tion control shaders, tessellation evaluation shaders, geometry shaders, and
fragment shaders. This expanded view of the pipeline is shown in Figure 3.1,
where the positions of the shaders in the pipeline suggest the functions that
each provides. While it is not obvious from the diagram, each shader block is
in an alternate branch of the pipeline; they are optional capabilities that may or
may not be used for any application. You may use any combination of vertex,
tessellation, geometry, or fragment shaders in your program; you do not have
to use any particular combinations, although, in general, if you use any shad-
40
3. Fundamental Shader Concepts
ers, you usually are required to include a vertex
shader, too.
When you’re developing shaders, however,
you don’t necessarily need to think of the entire
graphics pipeline like this. For each individual
shader, it is helpful to understand what data
comes into this shader, what this shader can do
with it, and what new data gets transmied to
the next stage. For this, it’s interesting to consider
how the graphics pipeline looks to shaders; this
is shown in Figure 3.2, with an emphasis on how
data moves among the shader stages. Of course,
if you choose not to include any shader stage, the
in/out variables from the previous stage simply
skip the omied stage and go on to the subsequent
stage.
Notice in Figure 3.2 that all aribute variables
are input to the vertex shader, and all uniform vari-
ables are input to whatever shader needs them.
Uniform variables are wrien by the application;
none of them can be wrien by any shader. Any
computation that needs to pass data on to the next
shader must do so through an
out variable, and
that variable must be read (as an
in variable) and
passed along (as an
out variable) by intermediate
variables until it is used.
Let’s consider how the separate functional-
ities of the graphics pipeline might be enhanced by
using shaders. To begin, let’s look at the modeling
functions that begin the geometry pipeline. In the
standard pipeline, you dene the vertices of your
model either by using specic statements, such as
glVertex3f(2.0, -1.0, 3.0),
or by using a computation to create the vertex coordinates. You can add other
geometric information such as normals and texture coordinates as you need
them and as they are available. You can also add appearance information.
This may be done while the geometry is dened, as you might do with colors
through the
glColor*(...) function. Another approach to appearance denes
and enables environments such as lighting, with its associated materials de-
nition, or textures, with their associated texture parameters, texture environ-
ment, and texture image.
Figure 3.1. The expanded graphics pipeline,
with programmable stages shown in green
and xed-function stages shown in orange.

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