Graphics Reference
In-Depth Information
Chapter 33
Shaders
33.1 Introduction
This chapter is about shaders, pieces of code written in a shading language,
a specialized language that's designed to make shader writing easy. Shaders
describe how to process data in the graphics pipeline. Shading languages are
evolving so fast (as is the programmability of the pipeline itself) that this chapter
will be out of date before its last sentence is written, let alone before you read it.
Despite this rapid evolution, there are some things that are invariant across sev-
eral generations of shading languages, and that we anticipate will remain in future
versions for at least a decade. There's some reason to believe this. The evolution
of the graphics libraries that link a program on a CPU to one or more programs
on the GPU has been from the specific (in early years) to the general, to the point
where much of GL 4 resembles an operating system rather than a graphics library:
It's concerned with linking together executable pieces of programs on the CPU
and GPU, passing data between processes, starting and stopping threads of execu-
tion, etc. There's no obvious further generalization that can happen, at least in the
near term. Perhaps in five years you'll write shaders directly in C# rather than in
a specialized shading language, and those shaders will run on 500-core machines.
But in many ways they'll continue to look the same: The first thing we usually do
with vertex data is to transform it to world-space coordinates using multiplication
by some matrix. That will look the same, no matter what the language.
We'll therefore describe a few shaders, using GL 4 as our reference system,
and trusting that you, the reader, will be able to interpret the ideas of this chapter
into whatever shading language you're using.
33.2 The Graphics Pipeline in Several Forms
Figures 33.1 and 33.2 show the various steps involved in either a rasterizing ren-
derer or a ray tracer, as described in Chapter 15.
927
 
 
 
 
Search WWH ::




Custom Search