   [DX9 Problem] Normal Mapping Skinned Mesh
  Hello :)I have my code for displaying skinned mesh and it used to work fine.Now I tried to change the FVF so I have bi-normal and tangents using Clone Mesh like this, it works fine if the mesh isn't skinned. But if it is, the vertices looks extruded and trianglish. Which is weird, as it still works fine for non-skinned ones.Here is the code:D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];UINT numElems = 0;if (FAILED(sVertN::FVF->GetDeclaration(elems, &numElems))){}pMeshData->pMesh->CloneMesh(D3DXMESH_MANAGED, elems, GraphicsDevice->GetDeviceCOM(), &pMeshContainer->MeshData.pMesh);if (FAILED((D3DXComputeTangentFrameEx(  pMeshContainer->MeshData.pMesh, // Input mesh  D3DDECLUSAGE_TEXCOORD, 0, // Vertex element of input tex-coords.   D3DDECLUSAGE_BINORMAL, 0, // Vertex element to output binormal.  D3DDECLUSAGE_TANGENT, 0,  // Vertex element to output tangent. D3DDECLUSAGE_NORMAL, 0,   // Vertex element to output normal. D3DXTANGENT_GENERATE_IN_PLACE, // Options pAdjacency, // Adjacency  0.01f, 0.25f, 0.01f, // Thresholds for handling errors  &pMeshContainer->MeshData.pMesh, // Output mesh  0))))    // Vertex Remapping{//}With this being my FVF:struct sVertN{D3DXVECTOR3 Position;D3DXVECTOR3 Normal;float u, v;D3DXVECTOR3 Tangent;D3DXVECTOR3 BiNormal;static IDirect3DVertexDeclaration9* FVF;};And it works fine for non skinned meshes. But when used on a skinned mesh, all the vertices suddenly look "extruded" in a way.It is not due to the normal shader, I tried my old shader with cloning the mesh and it still does that. If I reset the cloning to the old method it works fine again (with both shaders, but of course Normal Mapping won't work without Bi-normals and Tangents .Any ideas what it could be?This is the old method to clone the mesh:pMeshData->pMesh->CloneMeshFVF(D3DXMESH_MANAGED, pMeshData->pMesh->GetFVF(), GraphicsDevice->GetDeviceCOM(), &pMeshContainer->MeshData.pMesh);Which resides in CAllocateHierarchy::CreateMeshContainerAnd also in cModel::SetupBoneMatrices(LPFRAME pFrame, LPD3DXMATRIX pParentMatrix)(Both methods had been replaced with the method to include the new FVF).P.S. I am not getting any debug errors with DirectX debugging on maximum.[EDIT]Here is the code for initializing the FVFD3DVERTEXELEMENT9 NMapVertexElements[] = {{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},{0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0},D3DDECL_END()};if (GraphicsDevice->GetDeviceCOM()->CreateVertexDeclaration(NMapVertexElements, &sVertN::FVF) == false){} [Edited by - Shanee on June 7, 2010 10:20:10 AM]
  CreateVertexDeclaration() doesn't return a bool, you should use the FAILED macro instead.   ;Quote:Original post by Gage64CreateVertexDeclaration() doesn't return a bool, you should use the FAILED macro instead.Thank you but the CreateVertexDeclaration didn't fail.   ;  Ive had similar problem before...The only difference between your code and my code is that I set Adjecency parameter in D3DXComputeTangentFrameEx() function to NULL and my vertex declaration looks like this: D3DVERTEXELEMENT9 vertexDecl[] ={{ 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },{ 0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 },{ 0, 48, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },{ 0, 56, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT,  0 },{ 0, 68, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },D3DDECL_END()};I assume you converted your mesh to indexed-blended mesh first.Also, this vertex declaration must match input structure of your shader.I Hope this helps   ;  I found the problem, it was a silly mistake, I forgot a call to:pSkinInfo->SetDeclaration(elems);Thanks :)I wonder though, do I need to add D3DDECLUSAGE_BLENDWEIGHT and D3DDECLUSAGE_BLENDINDICES to the skinned mesh structure? I am not passing it to the shader after all.What are you using them for, SIIYA?   ;  for calculating vertex position and normal based on bone influences contained in BlendWeights vector.   