Sign in to follow this  
JokerX

How to add tangent element on skinned model

Recommended Posts

I want to apply normal mapping on skinned models. For that I need tangents info in the vertex format. On non-skinned models it works fine, but skinned model after reformat won't render. Here's the code:
DWORD		dwVertexStride = pTempMesh->GetNumBytesPerVertex ();
LPD3DXMESH	pClonedMesh;
D3DVERTEXELEMENT9 meshDeclaration[MAX_FVF_DECL_SIZE];

// returns only position, normal and first texture cooordinates... no blend weights or indices!
if (SUCCEEDED (pTempMesh->GetDeclaration (meshDeclaration)))
{
	DWORD dwNumDeclarations = 0;
	for (DWORD i=0; (i < MAX_FVF_DECL_SIZE) && (meshDeclaration[i].Stream != 0xFF); i++)
		dwNumDeclarations++;
	// adding tangent element
	meshDeclaration[dwNumDeclarations].Stream = 0;
	meshDeclaration[dwNumDeclarations].Offset = (WORD)dwVertexStride;
	meshDeclaration[dwNumDeclarations].Type = D3DDECLTYPE_FLOAT3;
	meshDeclaration[dwNumDeclarations].Method = D3DDECLMETHOD_DEFAULT;
	meshDeclaration[dwNumDeclarations].Usage = D3DDECLUSAGE_TANGENT;
	meshDeclaration[dwNumDeclarations].UsageIndex = 0;
	// ending element
	memset (&meshDeclaration[dwNumDeclarations+1], 0, sizeof(D3DVERTEXELEMENT9));
	meshDeclaration[dwNumDeclarations+1].Stream = 0xFF;
	meshDeclaration[dwNumDeclarations+1].Type = D3DDECLTYPE_UNUSED;

	if (SUCCEEDED (pTempMesh->CloneMesh (pTempMesh->GetOptions(), meshDeclaration, g_pd3dDevice, &pClonedMesh)))
	{
		pTempMesh->Release ();
		pTempMesh = pClonedMesh;
	}
	else
		goto e_Exit;
}
hr = pTempMesh->UpdateSemantics (meshDeclaration);
// compute tangents
hr = D3DXComputeTangent (pTempMesh, 0, 0, D3DX_DEFAULT, 0, pAdjacency);



Mesh->GetDeclaration() returns declaration info only about position, normal and textur coords, no info about blend weights or indices. When I newly set vertex declaration blend weights and blend indices are missing (so I suppose this may be a problem). Or have someone any idea what is wrong with this code? Someone was trying to make normal mapping on skinned models? [Edited by - JokerX on June 10, 2006 3:20:51 PM]

Share this post


Link to post
Share on other sites
Are you using software skinning? If so, the you have the bone weights and indices in the ID3DXSkinInfo interface and use the UpdateSkinnedMesh method to update the vertices in the mesh each frame. So in that situation, the vertex buffer does not have the bone data.

If you are using hardware skinning (done in shader), then you need to use the ConvertToIndexedBlendedMesh or ConvertToBlendedMesh functions to have the bone data added to the vertex buffer.

For normal mapping you need to add Tangets and Binormals. Frank Luna's new book covers how to do normal mapping. It also has a chapter on skinned meshes using hardware skinning.

The MultiAnimation sample in the SDK shows 4 ways to render a skinned mesh with software and hardware emthods.

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