Sign in to follow this  
george7378

Problem with D3DXComputeTangentFrame

Recommended Posts

george7378    1441

Hi everyone,

 

I have recently decided to mess with a mesh in Blender, and I didn't change much - I just removed about 50 vertices and replaced them with about 50 more (basically, just added a few cylinders in place of some old cylinder-like objects) and now I get the following problems when I try to compute the tangent frame for normal mapping:

 

D3DX: D3DXComputeTangentFrame: Warning: vertex 13296 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13297 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13298 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13317 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13318 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13319 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13345 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13346 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13347 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13366 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13367 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Warning: vertex 13368 has zero normal, results not guaranteed!
D3DX: D3DXComputeTangentFrame: Unable to create consistent tangent frames in this mesh without splitting vertices.

 

The vertex warnings actually appeared before, so that's nothing new (I have recalculated the normals in Blender many times, but it still gives me these 'no normal' warnings) but the last line is what is causing D3DXComputeTangentFrame to fail, and hence, my program doesn't run. Any ideas what could be causing the problem? I have no idea what it means!

 

Thanks!

Share this post


Link to post
Share on other sites
MJP    19754

In certain cases vertices will need to be split in order to generate consistent tangent frames for all triangles. The most common and easy-to-understand case is when UV's are mirrored across a vertex. Here's a crude diagram showing what I mean:

 

(0, 0) ============ (1, 0) ============= (0, 0)

 |                    |                     |

 |                    |                     |

 |                    |                     |

 |                    |                     |

 |                    |                     |

 |                    |                     |

(0, 1) ============ (1, 1) ============= (0, 1)

 

So here we have two quads using 6 verts, with UV coordinates shown for each vertex. To generate tangents and bitangents for these vertices, we look at how the UV coordinates are changing going from one vertex to the next. The bitangent is simple in this case: it's always increasing in the downward direction, so the bitangent will be (0, -1, 0) for all 6 verts. However the tangent is not so simple. This is because the U coordinate increases going from the left verts to the middle verts, but then decreases again going from the middle vert to the right vert. So for the leftmost verts you want a tangent of (1, 0, 0), and for the rightmost vert you want a tangent of (-1, 0, 0). For the middle verts however there is no tangent value we can use that will work correctly with both the left quad and the right quad. To deal with this we have to split the middle verts, so that you have one with  a tangent of (1, 0, 0) for the left quad and one with a tangent of (-1, 0, 0) for the right quad.

D3DXComputeTangentFrame will not split vertices, since it tries to put the tangent/bitangent data in the same mesh that it's using as an input. If you need to split verts, then you need to use D3DXComputeTangentFrameEx which can output a different mesh than the input mesh with a different number of vertices.

Share this post


Link to post
Share on other sites
george7378    1441

Thanks for the info - I don't see how it could suddenly be problematic when all I did was edit a few vertices, but I don't know much about the inner workings of meshes. First, is it possible to identify the culprit UV vertices in Blender? (I'm right in thinking that it hasn't got anything to do with the vertices themselves, but rather the UV coordinates?) - if I could find them in Blender I could probably move them around a bit. If not ... I guess I'll try D3DXComputeTangentFrameEx, although there seem to be a lot of terms in that function which I don't understand!

 

Thanks.

Share this post


Link to post
Share on other sites
george7378    1441

OK, I changed my code so that it does this instead:

 

    if (FAILED(D3DXComputeTangentFrameEx(texturedMesh, D3DDECLUSAGE_TEXCOORD, 0, D3DDECLUSAGE_BINORMAL, 0, D3DDECLUSAGE_TANGENT, 0, D3DDECLUSAGE_NORMAL, 0, 0, 0, 0.01f, 0.25f, 0.01f, &texturedMesh, 0)))
    {return false;}

 

I think this is OK usage of the function? There's a lot of stuff in there which I'm not really sure of! The program seems to run OK though, so I guess it's no problem...

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