Game Development Reference
In-Depth Information
Chapter 15
3D Vertex and Pixel Shaders
Shaders are rapidly dominating 3D graphics architecture. There are a few platforms
out there that don
t support shaders, such as the Nintendo Wii, which still uses fixed-
function pipelines. But when even smart phones start to use shaders, it is high time
to dig in and figure them out. Much of my own learning about them was pretty frus-
trating. It seemed there was no middle ground between drawing a very lame triangle
and drawing fur. I hope the following introduction will help you see a path to getting
started with shaders.
A shader is a program that can affect the position of a vertex, the color of a pixel, or
both. Shaders can create interesting effects by manipulating geometry, as is frequently
done for water surfaces, or changing the appearance of something as mundane as a
teapotahedron (see Figure 15.1).
Shaders can be written in assembly or high-level languages. Microsoft developed
HLSL, which stands for High Level Shader Language, for use within DirectX. There
is a standard for OpenGL called GLSL and Nivida
'
s Cg, or C for Graphics, which are
similar to HLSL. All look and feel a lot like C, but don
'
'
'
tC.
Just like any high-level language, shaders compile to assembler language. The shader
compiler lives in your graphics drivers, and depending on your graphics card,
the compiler can do some pretty interesting things with the resulting assembly. One
example is loops, which are generally unrolled instead of actually looping in the way
you are used to. Different shader versions have drastically different support for num-
bers of texture coordinates or even the size of the shader.
t be fooled. They aren
499
 
 
 
Search WWH ::




Custom Search