Game Development Reference
In-Depth Information
Shaders—Programs on the Graphics Card
The term shader is a bit misleading. Initially, shader programs were primarily
used to shade models by operating on the pixels that make up the surface of each
polygon. Over time the abilities of shader programs have expanded; they can
now change vertex properties, create new vertices, or even complete general
operations.
Shaders operate differently from normal programs that run on the CPU. Shader
programs are executed on a large number of elements all at the same time. This
means that shader programs are massively parallel, whereas programs on the
CPU are generally run serially and only one instance at a time. Shader programs
are excellent for doing operations on the mass of pixels and vertices that are the
building blocks of a 3D world.
Until recently there were three kinds of shaders—vertex, geometry, and pixel—
and each could do only certain operations. Vertex shaders operated on vertices;
pixel shaders on pixels; and geometry shaders on primitives. To reduce com-
plexity and allow hardware makers to optimize more efficiently, all these types of
shaders were replaced with one called the unified shader.
Shaders are programmed in special languages that run on the graphics card. At
the moment, these languages are a lot lower level than C++ (never mind C#).
OpenGL has a shading language called GLSL or Open GL Shading Language. It's
a little like C with lots of special operations for dealing with vectors and matrices.
DirectX also has its own shading language called HLSL or High Level Shading
Language. Both these languages are quite similar. To add to the confusion, there
is a third language called Cg, which was developed by Microsoft and Nvidia; it is
quite similar to HLSL.
Shaders in games are excellent for creating computationally heavy special effects
like lighting of parallax mapping. The current technology makes shader pro-
grams useful for little else. This topic will concentrate on game programming;
therefore, the programmable pipeline won't be covered as it's a rather large
topic. If you are interested, check the recommended reading section for several
excellent topics.
Shaders are on the cusp of becoming used for general parallel programming tasks
rather than just graphics. For instance, the Nvidia PhysX library allows physics
calculations to be done on the GPU rather than the CPU, resulting in much
 
Search WWH ::




Custom Search