• Advertisement
Sign in to follow this  

Computing tangents

This topic is 2823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I am trying to get normal maps on my code but the models I have do not have neither the tangents or the binormals. Is there anyway of calculating these on the code?. I tried using D3DXComputeTangent() like this
D3DXLoadMeshFromX(path, D3DXMESH_MANAGED, device, &aBuff, &mBuff, 0, &nSub, &meshHandle);

const D3DVERTEXELEMENT9 g_vertexDecl[] = {
   {0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
   {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 },
   {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,  0 },
   {0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
   D3DDECL_END()};

LPD3DXMESH newMesh = NULL;
HRESULT hr = meshHandle->CloneMesh(D3DXMESH_MANAGED, g_vertexDecl, device, &newMesh);

DWORD* pAdjacent = new DWORD[(3 * newMesh->GetNumFaces()) * sizeof(DWORD)];
hr = D3DXComputeTangent(newMesh, 0, 3, D3DX_DEFAULT, true, pAdjacent);
meshHandle = newMesh;
but the D3DXComputeTangent fails. Any suggestions why? Any other ways off doing this? Cheers

Share this post


Link to post
Share on other sites
Advertisement
You're passing "3" as your usage index for your tangent, while your tangent in your vertex declaration has a usage index of 0.

Also if you have D3D or D3DX functions failing, you can turn on the debug runtimes and you'll usually get information on why they failed in the debug spew.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement