Jump to content
  • Advertisement
Sign in to follow this  
JokerX

fx normal mapping and .x files

This topic is 4524 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 would like to add normal mapping to the x-meshes through the DX effects, but it does not look correctly. I think problem may be something with tangent and binormal, which x file does not includes. How can I change the x file to support normal mapping? Shoudl I use CloneMesh(), or UpdateSemantics()? ... but how?

Share this post


Link to post
Share on other sites
Advertisement
You should first allocate space for the tangent and binormal vectors by calling CloneMesh and then using D3DXComputeTangent to have D3D calculate them for you based on your existing texture coordinates and normals.

Share this post


Link to post
Share on other sites
Thanks for the replies, but there's still problem with tangent/binormal generation. D3DXComputeTangent() just don't work. Here is the code...



D3DVERTEXELEMENT9 meshDeclaration[MAX_FVF_DECL_SIZE];
DWORD dwVertexStride = pTempMesh->GetNumBytesPerVertex ();

if (SUCCEEDED (pTempMesh->GetDeclaration (meshDeclaration)))
{
DWORD dwNumDeclarations = 0;
for (i=0; (i < MAX_FVF_DECL_SIZE) && (meshDeclaration.Stream != 0xFF); i++)
dwNumDeclarations++;
// tangent
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;
// binormal
meshDeclaration[dwNumDeclarations + 1].Stream = 0;
meshDeclaration[dwNumDeclarations + 1].Offset = (WORD)(dwVertexStride + 3*sizeof(float));
meshDeclaration[dwNumDeclarations + 1].Type = D3DDECLTYPE_FLOAT3;
meshDeclaration[dwNumDeclarations + 1].Method = D3DDECLMETHOD_DEFAULT;
meshDeclaration[dwNumDeclarations + 1].Usage = D3DDECLUSAGE_BINORMAL;
meshDeclaration[dwNumDeclarations + 1].UsageIndex = 0;
// ending element
memset (&meshDeclaration[dwNumDeclarations + 2], 0, sizeof(D3DVERTEXELEMENT9));
meshDeclaration[dwNumDeclarations + 2].Stream = 0xFF;
meshDeclaration[dwNumDeclarations + 2].Type = D3DDECLTYPE_UNUSED;

if (SUCCEEDED (pTempMesh->CloneMesh (pTempMesh->GetOptions(), meshDeclaration, g_pD3DDevice, &pClonedMesh)))
{
// return S_OK
pTempMesh->Release ();
pTempMesh = pClonedMesh;
}
}

pTempMesh->UpdateSemantics (meshDeclaration); // return S_OK

// tangent/binormal computing
D3DXComputeTangent (pTempMesh, 0, 0, 0, 1, pdwAdjacency); // return S_OK





Than when I lock vertex buffer and look to the tangents/binormals there are all zeros. Model is pure box with 24 vertices and with texture coordinates already presented. What should I do to properly compute tan/bin ?

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!