Partager via


Texture Read

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

When a stage needs to fetch a color from the texture map--such as with the D3DMTA_TEXTURE operation (see D3DMTA Values)--it reads the current texture map for the stage and the interpolated texture coordinate for the current pixel.

The basic form of a texture read is to simply read the texel that corresponds to the given texture coordinates and return that color value. Microsoft® Direct3D Mobile® utilizes the following formulas to convert texture coordinates (u, v) into texel addresses (Tx, Ty).

T<SUB>x</SUB> = (M<SUB>x</SUB> * u) - 0.5
T<SUB>y</SUB> = (M<SUB>y</SUB> * v) - 0.5

In these formulas Mx and My are the width and height of the current texture map.

If the texture coordinates do not fall in the range 0.0 to 1.0, Direct3D Mobile uses a texture addressing mode to resolve the coordinate.

Texture Addressing

Texture Addressing controls how Direct3D Mobile remaps texture coordinates that are outside of the range of 0.0 to 1.0. You can control the addressing mode via the D3DMTSS_ADDRESSU, D3DMTSS_ADDRESSV, and D3DMTSS_ADDRESSW texture stage states (see D3DMTEXTURESTAGESTATETYPE). These states accept values from the D3DMTEXTUREADDRESS enumeration.

Texture Filtering

While it is possible for you to simply read the texel corresponding to the texture coordinates, this method introduces a number of aliasing effects. Direct3D Mobile supports a number of texture filtering modes that mitigate aliasing effects when generating the texture read values.

Many aliasing effects are introduced by point sampling a texture map either too frequently or too infrequently. For example, when a small texture map is mapped to a very large range of pixels the sampling can be too frequent. The other extreme, infrequency, occurs when a large texture range is mapped to a small number of pixels. Direct3D Mobile is able to detect these conditions by comparing the pixel area of a primitive to the pixel area of the current texture map and apply either a magnification or a reduction filter to compensate.

You can control the algorithms used in these filters on a per stage basis using the D3DMTSS_MAGFILTER and D3DMTSS_MINFILTER texture stage states. Each of these texture stage states accepts values from the D3DMTEXTUREFILTER enumeration.

Mipmaps

In addition to texture filtering, Direct3D Mobile supports mipmaps to allow applications to provide down-sampled texture images for different ranges. In fact, Direct3D Mobile treats all texture maps as mipmaps with regular texture maps simply regarded as single-level mipmaps.

Mipmaps allow the driver to sample from a map that has already been down-sampled to a level that is appropriate for the amount of screen area that the primitive covers.

Direct3D Mobile also allows the driver to interpolate between samples from two adjacent mipmap levels for still better results.

You can control mipmaps with the D3DMTSS_MIPFILTER texture stage state (see D3DMTEXTURESTAGESTATETYPE). The value that you set for this state controls whether Direct3D Mobile automatically selects a mipmap level or interpolates between two mipmap levels.

You can also bias the selection of mipmap levels by setting a value for the D3DMTSS_MIPMAPLODBIAS texture stage state. Positive values cause Direct3D Mobile to use lower resolution levels and negative numbers cause Direct3D Mobile to use higher resolution levels.

You can also explicitly limit the maximum level of detail that the rasterizer can use by setting the value of the D3DMTSS_MAXMIPLEVEL texture stage state. You can use this value to block Direct3D Mobile from using the mipmap levels with the highest level of detail in them.

See Also

Concepts

Texture Mapping