Platform SDK: DirectX |
The following are some ways you might use texture coordinate processing to achieve special texturing effects, expressed with pseudo-code.
Animating textures (by translation or rotation) on a model:
// 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);
SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)
// 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 = D3DUtil_SetIdentityMatrix(); // declared in d3dutil.h M._31 = du; M._32 = dv;
Creating texture coordinates as a linear function of a model's camera-space position:
// The input vertices have NO texture coordinates (saving bandwidth!!!) // 3 texture coordinates are generated by using vertex position in // camera space (x, y, z) SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION)
// Two output coordinates will be used. SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)
// Generate texture coordinates as linear functions // such 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(D3DTRANSFORMSTATE_TEXTURE0, &M)
Performing environment mapping with a cubic environment map:
SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR)
SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3)
Performing projective texturing:
SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION)
// Two output coordinates will be used. SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTF_PROJECTED | D3DTTFF_COUNT3)
The following are some ways you might use texture coordinate processing to achieve special texturing effects, expressed with pseudo-code.
Animating textures (by translation or rotation) on a model:
' Use a single texture, with 2-D texture coordinates. This ' bit-pattern should be expanded to include position, normal, ' and color information as needed. lFVFTex = (D3FVF_TEX1 Or D3DFVF_TEXCOORDSIZE2(0))
SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)
' 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 0 0 (du and dv change each frame) ' 0 0 0 0 dx.IdentityMatrix(M) M.rc31 = du M.ec32 = dv
Creating texture coordinates as a linear function of a model's camera-space position:
' The input vertices have NO texture coordinates (saving bandwidth!!!) ' 3 texture coordinates are generated by using vertex position in ' camera space (x, y, z) SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION)
' Two output coordinates will be used. SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)
' Generate texture coordinates as linear functions ' such 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(D3DTRANSFORMSTATE_TEXTURE0, M)
Performing environment mapping with a cubic environment map:
SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR)
SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3)
Performing projective texturing:
SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION)
' Two output coordinates will be used. SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTF_PROJECTED | D3DTTFF_COUNT3)