Game Development Reference
In-Depth Information
DWORD Value
);
Note: A particular sampler stage index i is associated with the i th
texture stage. That is, the i th sampler stage specifies the sampler states
for the i th set texture.
The texture/sampler stage index identifies the texture/sampler stage to
which we wish to set the texture/sampler. Thus, we can enable multiple
textures and set their corresponding sampler states by using different
stage indices. Previously in this topic, we always specified 0, denoting
the first stage because we only used one texture at a time. So for exam-
ple, if we need to enable three textures, we use stages 0, 1, and 2 like
this:
// Set first texture and corresponding sampler states.
Device->SetTexture( 0, Tex1);
Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
// Set second texture and corresponding sampler states.
Device->SetTexture( 1, Tex2);
Device->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
// Set third texture and corresponding sampler states.
Device->SetTexture( 2, Tex3);
Device->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
This code enables Tex1 , Tex2 , and Tex3 and sets the filtering modes
for each texture.
18.1.2 Multiple Texture Coordinates
Recall from Chapter 6 that for each 3D triangle, we want to define a
corresponding triangle on the texture that is to be mapped to the 3D
triangle. We did this by adding texture coordinates to each vertex.
Thus, every three vertices defining a triangle defined a corresponding
triangle on the texture.
Since we are now using multiple textures, for every three vertices
defining a triangle we need to define a corresponding triangle on each
of the enabled textures. We do this by adding extra sets of texture coor-
dinates to each vertex—one set for, and that corresponds with, each
enabled texture. For instance, if we are blending three textures
together, then each vertex must have three sets of texture coordinates
Search WWH ::




Custom Search