Sign in to follow this  
JokerX

fx normal mapping and .x files

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
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[i].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

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