Microsoft DirectX 8.1 (pixel shader versions 1.0, 1.1, 1.2, 1.3, 1.4) |
Texture addressing is the mechanism by which texture coordinates are either retrieved directly or used to sample data from a texture.
Texture coordinates can be supplied as part of the vertex format or can be read from certain kinds of texture maps. Texture coordinates are commonly referred to as TCs. A two-dimensional (2-D) texture map is addressed (or looked up) using (UV) coordinates, a 3-D texture map (cube map or volume map) is addressed using (UVW) texture coordinates. Alternately, texture coordinates can be used directly (with no lookup).
Sampling occurs when a texture coordinate is used to address the texel data at a particular location. This is also commonly referred to as performing a texture lookup. In order to sample a texture, it must first be associated with a texture stage. The actual data sampled at the texture coordinate address is controlled by four things.
The following diagram shows ways that texture coordinates are used for texture addressing.
For pixel shader version 1.0 to 1.3, texture coordinates are used in three ways:
For pixel shader version 1.4, the texture registers (t#) have a different meaning than previous pixel shader versions. They contain texture coordinates so they should be thought of as texture coordinate registers. These texture coordinate registers are read only (used as source parameters for texture addressing instructions) and are not available to arithmetic instructions.
Having texture coordinates in their own register means that the texture coordinate set and the texture stage number can be different in pixel shader version 1.4 texture addressing instructions. The texture stage number from which to sample is determined by the destination register number, but the texture coordinate set is determined by the new source (t#) register specified.
The "Modify TCs" box in the previous diagram does not apply to pixel shader version 1.4 because modification of texture coordinates before texture sampling is simply accomplished using standard arithmetic instructions, followed by a dependent read. Dependent reads are described in the following diagram and text.
Often, it is useful to perform some operation on texture coordinates before using them to sample a texture. This is referred to as a dependent read. The term "dependent" indicates that the texture data that gets sampled depends on some result computed in the pixel shader.
For pixel shader version 1.0 to 1.3, dependent reads are limited to a texture addressing instruction using the result of a previous texture addressing instruction as a source parameter. For pixel shader version 1.4, the dependent reads are much more flexible in that the texture coordinates for a texture sample may be derived from the result of previous texture addressing instructions and/or arbitrary pixel shader arithmetic instructions. Dependent reads in pixel shader version 1.4 always involve an (r#) register being used as the texture coordinates for a texture address instruction. This means that the dependent read only occurs in phase 2. For more information about ordering arithmetic and texture addressing instructions within a shader, see instruction flow.