Chapter 9Chapter 9
Advanced Direct3D
While I covered a lot of ground in Chapter 8, I really only scratched the
I’ll have discussed everything you could ever want to know about texture
mapping, along with alpha blending, multitexture effects, and the stencil
With Direct3D, there eventually comes a crest in the learning curve. At
some point you know enough about the API that figuring out the rest is
easy. For example, there comes a point when you’ve been bitten enough by
setting the vertex shader parameters and zeroing out structures that you
automatically do it. Hopefully, after learning the material in this chapter,
you’ll be over the hump. When you get there, learning the rest of the API is
a breeze. Among the topics discussed in this chapter are:
Alpha blending
Texture mapping
Pixel shaders
Environment mapping
Stencil buffers
Alpha BlendingAlpha Blending
Up to this point, I’ve been fairly dismissive of the mysterious alpha compo
nent that rides along in all of the D3DColor structures. Now you may
finally learn its dark secrets. A lot of power is hidden away inside the alpha
Loosely, the alpha component of the RGBA quad represents the opacity
of a surface. An alpha value of 255 (or 1.0f for floating point) means the
color is completely transparent. Of course, the value of the alpha compo
nent is fairly meaningless unless you actually activate the alpha blending
step. If you want, you can set things up a different way, such as having 0
mean that the color is completely opaque. The meaning of alpha is
dependent on how you set up the alpha blending step.
The alpha blending step is one of the last in the D3D output merger
pipeline. As you rasterize primitives, each pixel that you wish to change in
the frame buffer gets sent through the alpha blending step. That pixel is
combined using blending factors to the pixel that is currently in the frame

Get Advanced 3D Game Programming with DirectX 10.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.