i
i
i
i
i
i
i
i
3.8. Effects 45
number of different operations. The most common are combinations of
multiplication, addition, and subtraction involving the color and alpha val-
ues, but other operations are possible, such as minimum and maximum,
as well as bitwise logic operations. DirectX 10 added the capability to
blend two colors from the pixel shader with the frame buffer color—this
capability is called dual-color blending.
If MRT functionality is employed, then blending can be performed on
multiple buffers. DirectX 10.1 introduced the capability to perform dif-
ferent blend operations on each MRT buffer. In previous versions, the
same blending operation was always performed on all buffers (note that
dual-color blending is incompatible with MRT).
3.8 Effects
This tour of the pipeline has focused so far on the various programmable
stages. While vertex, geometry, and pixel shader programs are necessary
to control these stages, they do not exist in a vacuum. First, an individual
shader program is not particularly useful in isolation: A vertex shader pro-
gram feeds its results to a pixel shader. Both programs must be loaded for
any work to be done. The programmer must perform some matching of the
outputs of the vertex shader to the inputs of the pixel shader. A particu-
lar rendering effect may be produced by any number of shader programs
executed over a few passes. Beyond the shader programs themselves, state
variables must sometimes be set in a particular configuration for these pro-
grams to work properly. For example, the renderer’s state includes whether
and how the Z-buffer and stencil buffer are each used, and how a fragment
affects the existing pixel value (e.g., replace, add, or blend).
For these reasons, various groups have developed effects languages, such
as HLSL FX, CgFX, and COLLADA FX. An effect file attempts to encap-
sulate all the relevant information needed to execute a particular rendering
algorithm [261, 974]. It typically defines some global arguments that can
be assigned by the application. For example, a single effect file might define
the vertex and pixel shaders needed to render a convincing plastic material.
It would expose arguments such as the plastic color and roughness so that
these could be changed for each model rendered, but using the same effect
file.
To show the flavor of an effect file, we will walk through a trimmed-
down example taken from NVIDIA’s FX Composer 2 effects system. This
DirectX 9 HLSL effect file implements a very simplified form of Gooch
shading [423]. One part of Gooch shading is to use the surface normal and
compare it to the light’s location. If the normal points toward the light, a
warm tone is used to color the surface; if it points away, a cool tone is used.