D3DXComputeTangentFrameEx function

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.

Syntax

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

Parameters

pMesh [in]

Type: ID3DXMesh*

Pointer to an input ID3DXMesh mesh object.

dwTextureInSemantic [in]

Type: DWORD

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]

Type: DWORD

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]

Type: DWORD

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]

Type: DWORD

Specifies the semantic index at which to store the partial derivative with respect to the U texture coordinate.

dwVPartialOutSemantic [in]

Type: DWORD

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]

Type: DWORD

Specifies the semantic index at which to store the partial derivative with respect to the V texture coordinate.

dwNormalOutSemantic [in]

Type: DWORD

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]

Type: DWORD

Specifies the semantic index at which to store the normal vector at each vertex.

dwOptions [in]

Type: DWORD

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 )

 

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]

Type: const DWORD*

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 * GetNumFaces * sizeof(DWORD).

fPartialEdgeThreshold [in]

Type: FLOAT

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]

Type: FLOAT

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]

Type: FLOAT

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]

Type: ID3DXMesh**

Address of a pointer to an output ID3DXMesh mesh object that receives the computed tangent, binormal, and normal vector data.

ppVertexMapping [out]

Type: ID3DXBuffer**

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 value

Type: HRESULT

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

Requirement Value
Header
D3DX9Mesh.h
Library
D3dx9.lib

See also

Mesh Functions

D3DXComputeTangentFrame