Sign in to follow this  
shaqdx

D3DXComputeTangent problems with mesh

Recommended Posts

Hi, I am having annoying problems when rendering the tangent of a mesh. I can render the normals on its own just fine with D3DXComputeNormals(), but when rendering the tangent on it's own, I get a black colour covering the whole mesh. This happens with any mesh. I have tried D3DXComputeTangentFrame(), and the same problem occurs. Anyone know what the problem might be? Here is some code I have.
D3DVERTEXELEMENT9 elements[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },	
D3DDECL_END()
};

LPD3DXMESH temp;

m_pMesh->CloneMesh( D3DXMESH_MANAGED, elements, pd3dDevice, &temp ); 

m_pMesh->Release();
m_pMesh = temp;

if(FAILED(D3DXComputeNormals(m_pMesh, NULL)))
	return E_FAIL;

if(FAILED(D3DXComputeTangent(m_pMesh, 0, 0, 0, TRUE, NULL)))
	return E_FAIL;

Thanks. [Edited by - Muhammad Haggag on November 27, 2005 7:52:50 AM]

Share this post


Link to post
Share on other sites
The size of your Vertex Declaration is a bit off, you might want to try something looking like this as D3DXComputeTangentFrame() returns position, normal, texture coordinates, tangents and binormals.


D3DVERTEXELEMENT9 elements[] =
{
{ 0, sizeof( float ) * 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, sizeof( float ) * 3, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, sizeof( float ) * 6, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, sizeof( float ) * 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
{ 0, sizeof( float ) * 15, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
D3DDECL_END()
};

LPD3DXMESH temp;
if ( FAILED( pMesh->CloneMesh( D3DXMESH_MANAGED, elements, pDevice, &temp ) ) )
{
pMesh = NULL;
return;
}

pMesh->Release();
pMesh = temp;

D3DXComputeTangentFrame(pMesh, 0);



I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
I tried that, but I am still getting a black mesh. I don't understand why the normals would work but not the tangents.

In my shader, I have a "float4 POSITION" and "float2 TEXCOORD" that relates to the position and texture coordinates of the mesh, BUT in the vertex declaration as replied, the POSITION and TEXCOORD are both float3. Could this be a reason why the tangent isn't rendering. Is there anything else I can try?

Thanks for any help.

Share this post


Link to post
Share on other sites
use D3DXcomputetangentframeEX.
that way you can describe your inputs and outputs exactly
to your descriptor.
and turn debugging on. youll work it out, its piece of piss
unless you havent figured it out already.

Share this post


Link to post
Share on other sites
Hi,

I used D3DXComputeTangentFrameEx() and I am still not getting the correct results, although when debugging I do the get the folllowing message.


"D3DX: D3DXComputeTangentFrame: Unable to create consistent tangent frames in this mesh without splitting vertices."


Anyone know what I can try. I'm sure I've almost got it working.

Thanks

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