Sign in to follow this  
gabzuka

Computing tangents

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this