Microsoft DirectX 8.1 (Visual Basic) |
The following list contains examples of special effects accomplished with texture coordinate processing.
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. Three texture coordinates are generated by ' using vertex position in camera space (x, y, z). SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION)
' Two output coordinates are used. SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)
' Generate texture coordinates as linear functions ' so that: ' u = Ux*x + Uy*y + Uz*z + Uw ' v = Vx*x + Vy*y + Vz*z + 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 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 are used. SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTF_PROJECTED | D3DTTFF_COUNT3)