Freigeben über


Texture Coordinate Transformations (Windows CE 5.0)

Send Feedback

Microsoft® Direct3D® Mobile devices can transform the texture coordinates for vertices by applying a 4×4 matrix. The system applies transformations to texture coordinates in the same manner as geometry, and any transformations that can be communicated in a 4×4 matrix — scales, rotations, translations, projections, shears, or any combination of these — can be applied.

Note   Direct3D Mobile does not modify transformed and lit vertices. As a result, an application using transformed and lit vertices cannot use Direct3D Mobile to transform the texture coordinates of the vertices.

Devices that support hardware-accelerated transformation and lighting operations (TnLHAL Device) also accelerate the transformation of texture coordinates. When hardware acceleration of transformations is not available, platform-specific optimizations in the Direct3D Mobile geometry pipeline apply to texture coordinate transformations.

Texture coordinate transformations are useful for producing special effects while avoiding the need to directly modify the texture coordinates of your geometry. You could use simple translation or rotation matrices to animate textures on an object, or you can transform texture coordinates that are automatically generated by Direct3D Mobile to simplify and perhaps accelerate advanced effects such as projected textures and dynamic light-mapping. Additionally, you might use texture coordinate transforms to reuse a single set of texture coordinates for multiple purposes, in multiple texture stages.

Setting and Retrieving Texture Coordinate Transformations

Like the matrices that your application uses for geometry, you set and retrieve texture coordinate transformations by calling the IDirect3DMobileDevice::SetTransform and IDirect3DMobileDevice::GetTransform methods. These methods accept the D3DTS_TEXTURE0 through D3DTS_TEXTURE3 members of the D3DMTRANSFORMSTATETYPE enumerated type to identify the transformation matrices for texture stages 0 through 3, respectively.

Enabling Texture Coordinate Transformations

The D3DMTSS_TEXTURETRANSFORMFLAGS texture stage state controls the application of texture coordinate transformations. Values for this texture stage state are defined by the D3DMTEXTURETRANSFORMFLAGS enumerated type.

Texture coordinate transformations are disabled when D3DMTSS_TEXTURETRANSFORMFLAGS is set to D3DTTFF_DISABLE (the default value). Assuming that texture coordinate transformations were enabled for stage 0, the following code example disables them.

// For this example, the d3dmDevice variable contains a 
// valid pointer to an IDirect3DMobileDevice interface.

d3dmDevice->SetTextureStageState( 0, D3DMTSS_TEXTURETRANSFORMFLAGS,
D3DMTTFF_DISABLE );

The other values defined in D3DMTEXTURETRANSFORMFLAGS are used to enable texture coordinate transformations, and to control how many resulting texture coordinate elements are passed to the rasterizer. For example, take the following code.

// For this example, the d3dmDevice variable contains a 
// valid pointer to an IDirect3DMobileDevice interface.

d3dmDevice->SetTextureStageState( 0, D3DMTSS_TEXTURETRANSFORMFLAGS,
D3DMTTFF_COUNT2 );

The D3DMTTFF_COUNT2 value instructs the system to apply the transformation matrix set for texture stage 0, and then pass the first two elements of the modified texture coordinates to the rasterizer.

The D3DMTTFF_PROJECTED texture transformation flag indicates coordinates for a projected texture. When this flag is specified, the rasterizer divides the elements passed-in by the last element. Take the following code, for example.

// For this example, the d3dmDevice variable contains a 
// valid pointer to an IDirect3DMobileDevice interface.

d3dmDevice->SetTextureStageState( 0, D3DMTSS_TEXTURETRANSFORMFLAGS, 
                                   D3DMTTFF_COUNT3 | D3DMTTFF_PROJECTED );

This example informs the system to pass three texture coordinate elements to the rasterizer. The rasterizer divides the first two elements by the third, producing the 2-D texture coordinates needed to address the texture.

Using Texture Coordinate Processing

You can use texture coordinate processing to achieve special texturing effects. For example the following steps show how you could animate textures (by translation or rotation) on a model.

  • Define 2-D texture coordinates in your vertex format.

    // Use a single texture, with 2-D texture coordinates. This
    // bit-pattern should be expanded to include position, normal, 
    // and color information as needed.
    DWORD dwFVFTex = D3MFVF_TEX1 | D3DMFVF_TEXCOORDSIZE2(0);
    
  • Configure the rasterizer to use 2-D texture coordinates.

    SetTextureStageState(0, D3DMTSS_TEXTURETRANSFORMFLAGS, D3DMTTFF_COUNT2);
    
  • Define and set an appropriate texture coordinate transformation matrix.

    // M is a D3DMMATRIX being set to translate texture
    // coordinates in the U and V directions.
    //      1   0  0  0
    //      0   1  0  0
    //      du dv  1  0 (du and dv change each frame)
    //      0   0  0  1
    
    M._11 = 1.0;
    /* ... */
    M._31 = du; 
    M._32 = dv; 
    /* ... */
    M._44 = 1.0;
    

See Also

Texture Coordinates

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.