Game Development Reference
In-Depth Information
Note: As with blending in Chapter 7, the resulting image depends
on how the textures are blended. In the fixed function multitexturing
stage, the blending equation is controlled through texture render
states. With pixel shaders we can write the blend function program-
matically in code as a simple expression. This allows us to blend the
textures in any way we want. We elaborate on blending the textures
when we discuss the sample application for this chapter.
Blending the textures (two in this example) to light the crate has two
advantages over Direct3D's lighting:
The lighting is precalculated into the spotlight light map. There-
fore, the lighting does not need to be calculated at run time, which
saves processing time. Of course, the lighting can only be precalcu-
lated for static objects and static lights.
Since the light maps are precalculated, we can use a much more
accurate and sophisticated lighting model than Direct3D's model.
(Better lighting results in a more realistic scene.)
Remark: The multitexturing stage is typically used to implement a
full lighting engine for static objects. For example, we might have a
texture map that holds the colors of the object, such as a crate texture
map. Then we may have a diffuse light map to hold the diffuse surface
shade, a separate specular light map to hold the specular surface
shade, a fog map to hold the amount of fog that covers a surface, and
a detail map to hold small, high frequency details of a surface. When
all these textures are combined, it effectively lights, colors, and adds
details to the scene using only lookups into precalculated textures.
Note: The spotlight light map is a trivial example of a very basic
light map. Typically, special programs are used to generate light maps
given a scene and light sources. Generating light maps goes beyond
the scope of this topic. For the interested reader, Alan Watt and Fabio
Policarpo describe light mapping in 3D Games: Real-time Rendering
and Software Technology .
18.1.1 Enabling Multiple Textures
Recall that textures are set with the IDirect3DDevice9::Set-
Texture method and sampler states are set with the IDirect3D-
Device9::SetSamplerState method, which are prototyped as:
HRESULT IDirect3DDevice9::SetTexture(
DWORD Stage, // specifies the texture stage index
IDirect3DBaseTexture9 *pTexture
);
HRESULT IDirect3DDevice9::SetSamplerState(
DWORD Sampler, // specifies the sampler stage index
D3DSAMPLERSTATETYPE Type,
Search WWH ::




Custom Search