Game Development Reference
In-Depth Information
that index into the three enabled textures. Thus, a vertex structure for
multitexturing with three textures would look like this:
struct MultiTexVertex
{
MultiTexVertex(float x, float y, float z,
float u0, float v0,
float u1, float v1,
float u2, float v2)
{
_x = x; _y = y; _z = z;
_u0 = u0; _v0 = v0;
_u1 = u1; _v1 = v1;
_u2 = u2; _v2 = v2;
}
float _x, _y, _z;
float _u0, _v0; // Texture coordinates for texture at stage 0.
float _u1, _v1; // Texture coordinates for texture at stage 1.
float _u2, _v2; // Texture coordinates for texture at stage 2.
static const DWORD FVF;
};
const DWORD MultiTexVertex::FVF = D3DFVF_XYZ | D3DFVF_TEX3;
Observe that the flexible vertex format flag D3DFVF_TEX3 is specified
denoting the vertex structure contains three sets of texture coordi-
nates. The fixed function pipeline supports up to eight sets of texture
coordinates. To use more than eight, you must use a vertex declaration
and the programmable vertex pipeline.
Note: In the newer pixel shader versions, we can use one texture
coordinate set to index into multiple textures, thereby removing the
need for multiple texture coordinates. Of course this assumes the
same texture coordinates are used for each texture stage. If the texture
coordinates for each stage are different, then we will still need multi-
ple texture coordinates.
18.2 Pixel Shader Inputs and Outputs
Two things are input into a pixel shader: colors and texture coordinates.
Both are per pixel.
Note: Recall that vertex colors are interpolated across the face of a
primitive.
A per pixel texture coordinate is simply the (u, v) coordinates that
specify the texel in the texture that is to be mapped to the pixel in
question. Direct3D computes both colors and texture coordinates per
pixel, from vertex colors and vertex texture coordinates, before enter-
ing the pixel shader. The number of colors and texture coordinates
Search WWH ::




Custom Search