D3DXComputeTangentFrameEx

Performs tangent frame computations on a mesh. Tangent, binormal, and optionally normal vectors are generated. Singularities are handled as required by grouping edges and splitting vertices.

HRESULT D3DXComputeTangentFrameEx(
  ID3DXMesh * pMesh,
  DWORD dwTextureInSemantic,
  DWORD dwTextureInIndex,
  DWORD dwUPartialOutSemantic,
  DWORD dwUPartialOutIndex,
  DWORD dwVPartialOutSemantic,
  DWORD dwVPartialOutIndex,
  DWORD dwNormalOutSemantic,
  DWORD dwNormalOutIndex,
  DWORD dwOptions,
  CONST DWORD * pdwAdjacency,
  FLOAT fPartialEdgeThreshold,
  FLOAT fSingularPointThreshold,
  FLOAT fNormalEdgeThreshold,
  ID3DXMesh ** ppMeshOut,
  ID3DXBuffer ** ppVertexMapping
);

Parameters

pMesh
[in] Pointer to an input ID3DXMesh mesh object.
dwTextureInSemantic
[in] Specifies the texture coordinate input semantic. If D3DX_DEFAULT, the function assumes that there are no texture coordinates, and the function will fail unless normal vector calculation is specified.
dwTextureInIndex
[in] If a mesh has multiple texture coordinates, specifies the texture coordinate to use for the tangent frame computations. If zero, the mesh has only a single texture coordinate.
dwUPartialOutSemantic
[in] Specifies the output semantic for the type, typically D3DDECLUSAGE_TANGENT, that describes where the partial derivative with respect to the U texture coordinate will be stored. If D3DX_DEFAULT, then this partial derivative will not be stored.
dwUPartialOutIndex
[in] Specifies the semantic index at which to store the partial derivative with respect to the U texture coordinate.
dwVPartialOutSemantic
[in] Specifies the D3DDECLUSAGE type, typically D3DDECLUSAGE_BINORMAL, that describes where the partial derivative with respect to the V texture coordinate will be stored. If D3DX_DEFAULT, then this partial derivative will not be stored.
dwVPartialOutIndex
[in] Specifies the semantic index at which to store the partial derivative with respect to the V texture coordinate.
dwNormalOutSemantic
[in] Specifies the output normal semantic, typically D3DDECLUSAGE_NORMAL, that describes where the normal vector at each vertex will be stored. If D3DX_DEFAULT, then this normal vector will not be stored.
dwNormalOutIndex
[in] Specifies the semantic index at which to store the normal vector at each vertex.
dwOptions

Combination of one or more D3DXTANGENT flags that specify tangent frame computation options. If NULL, the following options will be specified:
Description D3DXTANGENT Flag Value
Weight the normal vector length by the angle, in radians, subtended by the two edges leaving the vertex. & !( D3DXTANGENT_WEIGHT_BY_AREA | D3DXTANGENT_WEIGHT_EQUAL )
Compute orthogonal Cartesian coordinates from texture coordinates (u, v). See Remarks. & !( D3DXTANGENT_ORTHOGONALIZE_FROM_U | D3DXTANGENT_ORTHOGONALIZE_FROM_V )
Textures are not wrapped in either u or v directions & !( D3DXTANGENT_WRAP_UV )
Partial derivatives with respect to texture coordinates are normalized. & !( D3DXTANGENT_DONT_NORMALIZE_PARTIALS )
Vertices are ordered in a counterclockwise direction around each triangle. & !( D3DXTANGENT_WIND_CW )
Use per-vertex normal vectors already present in the input mesh. & !( D3DXTANGENT_CALCULATE_NORMALS )

[in] If D3DXTANGENT_GENERATE_IN_PLACE is not set, the input mesh is cloned. The original mesh must therefore have sufficient space to store the computed normal vector and partial derivative data.

pdwAdjacency
[in] Pointer to an array of three DWORDs per face that specify the three neighbors for each face in the mesh. The number of bytes in this array must be at least 3 * ID3DXBaseMesh::GetNumFaces * sizeof(DWORD).
fPartialEdgeThreshold
[in] Specifies the maximum cosine of the angle at which two partial derivatives are deemed to be incompatible with each other. If the dot product of the direction of the two partial derivatives in adjacent triangles is less than or equal to this threshold, then the vertices shared between these triangles will be split.
fSingularPointThreshold
[in] Specifies the maximum magnitude of a partial derivative at which a vertex will be deemed singular. As multiple triangles are incident on a point that have nearby tangent frames, but altogether cancel each other out (such as at the top of a sphere), the magnitude of the partial derivative will decrease. If the magnitude is less than or equal to this threshold, then the vertex will be split for every triangle that contains it.
fNormalEdgeThreshold
[in] Similar to fPartialEdgeThreshold, specifies the maximum cosine of the angle between two normals that is a threshold beyond which vertices shared between triangles will be split. If the dot product of the two normals is less than the threshold, the shared vertices will be split, forming a hard edge between neighboring triangles. If the dot product is more than the threshold, neighboring triangles will have their normals interpolated.
ppMeshOut
[out] Address of a pointer to an output ID3DXMesh mesh object that receives the computed tangent, binormal, and normal vector data.
ppVertexMapping
[out] Address of a pointer to an output ID3DXBuffer buffer object that receives a mapping of new vertices computed by this method to the original vertices. The buffer is an array of DWORDs, with the array size defined as the number of vertices in ppMeshOut.

Return Values

If the function succeeds, the return value is S_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA, E_OUTOFMEMORY.

Remarks

A simplified version of this function is available as D3DXComputeTangentFrame.

The computed normal vector at each vertex is always normalized to have unit length.

The most robust solution for computing orthogonal Cartesian coordinates is to not set flags D3DXTANGENT_ORTHOGONALIZE_FROM_U and D3DXTANGENT_ORTHOGONALIZE_FROM_V, so that orthogonal coordinates are computed from both texture coordinates u and v. However, in this case, if either u or v is zero, then the function will compute orthogonal coordinates using D3DXTANGENT_ORTHOGONALIZE_FROM_V or D3DXTANGENT_ORTHOGONALIZE_FROM_U, respectively.

Requirements

Header: Declared in D3dx9mesh.h.

See Also

D3DXComputeTangentFrame