Texture coordinate processing
Overview:
For some special texture applications, it is necessary to deal with texture coordinates, including texture coordinate auto-generation and texture coordinate transformation.
Source of texture coordinates: from FVF and from Direct3D
Determines whether the texture coordinate transformation is enabled before the texture coordinates reach the raster processor.
first, the texture coordinates are automatically generated
Texture coordinates can be automatically generated through the Direct3D rendering engine for special visuals such as environment mapping. The automatic generation of texture coordinates is done in the Direct3D coordinate transformation and illumination pipeline, and the execution speed is faster.
The Direct3D system can use transformed spatial vertex position coordinates and normal information to generate texture coordinates.
The automatic generation of texture coordinates is mainly used to produce some special effects.
The D3dtss_texcoordindex texture stage state controls how the Direct3D system automatically generates texture coordinates. Coordinate generation Flags:
D3dtss_tci_passthru using the texture coordinates in vertex information
D3dtss_tci_cameraspacenormal the texture coordinate output of the texture layer with the normal vector of the vertex in the observing coordinate system
d3dtss_tci_cameraspaceposition Vertex coordinates in the observing coordinate system as the texture coordinate output of the texture layer
D3dtss_tci_reflectionvector as the texture coordinate output of the texture layer with the reflection vector of the vertex in the observing coordinate system, the reflection vectors are computed by vertex coordinates and normal vectors.
D3dtss_tci_spheremap the texture coordinates of the output spherical reflection
Pd3ddevice->settexturestagestate (0,d3dtss_texturecoordindex, d3dtss_tci_cameraspacenormal);
The texture stage state d3dtss_texturetransformflags is used to control the output generated by the texture coordinates.
Pd3ddevice->settexturestagestate (0,d3dtss_texturetransformflags, D3dttff_count2);
second, texture coordinate transformation
Direct3D provides the ability to coordinate transformations of the generated texture coordinates. You can specify a 4*4 texture coordinate transformation matrix, multiply it with the generated texture coordinates, and then output the transformed texture coordinates to the Direct3D rendering pipeline.
The following code pans the original texture coordinates (1.0,1.0,0.0)
D3DXMATRIX Mat;
D3DXMatrixIdentity (&mat);
mat.41 = 1.0f;
mat.42 = 1.0f;
mat.43 = 0.0f;
Pd3ddevice->settransform (D3DTEXTURE0, Mat);