Freigeben über


Using Texture Coordinate Processing

The following list contains examples of ways you might use texture coordinate processing to achieve special texturing effects.

Animating 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 = D3FVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0);
    
  • Configure the rasterizer to use 2-D texture coordinates.

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

    // M is a D3DMATRIX 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
    
    D3DMATRIX M = D3DXMatrixIdentity(); // declared in d3dutil.h
    M._31 = du; 
    M._32 = dv; 
    

Creating texture coordinates as a linear function of a model's camera-space position

  • Use the D3DTSS_TCI_CAMERASPACEPOSITION flag to instruct the system to pass the vertex position, in camera space, as input to a texture transformation.

    // The input vertices have no texture coordinates, saving 
    // bandwidth. Three texture coordinates are generated by 
    // using vertex position in camera space (x, y, z).
    SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,
    D3DTSS_TCI_CAMERASPACEPOSITION);
    
  • Instruct the rasterizer to expect 2-D texture coordinates.

    // Two output coordinates are used.
    SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS,
    D3DTTFF_COUNT2);
    
  • Define and set a matrix that applies a linear function.

    // Generate texture coordinates as linear functions 
    // so that:
    //      u = Ux*x + Uy*x + Uz*x + Uw 
    //      v = Vx*x + Vy*x + Vz*x + Vw
    // The matrix M for this case is:
    //      Ux  Vx  0  0 
    //      Uy  Vy  0  0 
    //      Uz  Vz  0  0 
    //      Uw  Vw  0  0 
    
    SetTransform(D3DTS_TEXTURE0, &M);
    

Performing projective texturing

  • Use the D3DTSS_TCI_CAMERASPACEPOSITION flag to instruct the system to pass the vertex position as input to a texture transformation matrix.

    SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);
    
  • Create and apply the texture projection matrix. This is beyond the scope of this documentation, and is the topic of several industry articles.

  • Instruct the rasterizer to expect three-element projected texture coordinates.

    // Two output coordinates are used.
    SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTF_PROJECTED | D3DTTFF_COUNT3);
    

See Also

Texture Coordinate Processing

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.