Jump to content
  • Advertisement
Sign in to follow this  

How to add tangent element on skinned model

This topic is 4490 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

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;

// 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.Stream != 0xFF); i++)
	// 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;
		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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!