Sign in to follow this  
Maddius

Compute Tangent

Recommended Posts

Hi all, If you loaded say an .x file or had any kind of geometry, how would you calculate the tangent vector at each vertex? I would like to be able to load a .x file in and then generate its tangents, or does the .x file store tangents if told too? If so how do you extract them? Thanks all.

Share this post


Link to post
Share on other sites
If you're using D3D9 then you can use D3DXComputeTangentFrameEx to generate tangents and binormals. I'm not sure if .X files can store tangents and binormals.

Unfortunately the DX10 version of D3DX doesn't have any equivalent. It is possible to create temporary D3D9 device and then create an ID3DXMesh so that you can generate the tangent frame, but it's a bit of work. Otherwise you're stuck with rolling your own functions, or using something third-party like NVMeshMender.

Share this post


Link to post
Share on other sites
Okay I am using Dx10, so how easy to use is NVMeshMender? Do you just supply the mesh data and it will return the tangents? Anybody used it before?

Share this post


Link to post
Share on other sites
I used it a long time ago...basically you just need to get your vertex data into into its library-specific structure and then you just call a function. I don't think it took me more than a few hours to get going.

Share this post


Link to post
Share on other sites
You can also calculate tangent vectors on your own it's not that difficult (I'm doing that way). Here is good article how to do that: http://www.terathon.com/code/tangent.html.

Share this post


Link to post
Share on other sites
Okay thats all fair enough, I have read that article before and its good. So what would be returned if I loaded a model I made in 3DS max say and I called GetVertexDescription on the mesh? What data would it hold?

Share this post


Link to post
Share on other sites
Does DX10 even have the D3DXLoadMeshFromX function? - I guess not, what is the most commonly used file format for importing models in Dx10?

Share this post


Link to post
Share on other sites
Quote:
Original post by Maddius
Does DX10 even have the D3DXLoadMeshFromX function? - I guess not, what is the most commonly used file format for importing models in Dx10?


Your own format.
No more X files or any 'native' format at all.


Share this post


Link to post
Share on other sites
Quote:
Original post by dys129
You can also calculate tangent vectors on your own it's not that difficult (I'm doing that way). Here is good article how to do that: http://www.terathon.com/code/tangent.html.



404 Page not found

Share this post


Link to post
Share on other sites
Quote:
Original post by brekehan
Quote:
Original post by Maddius
Does DX10 even have the D3DXLoadMeshFromX function? - I guess not, what is the most commonly used file format for importing models in Dx10?


Your own format.
No more X files or any 'native' format at all.


Okay when you say your own format, you mean the exporter must use your own custom format? I guess I would just make a custom file reader, cant seem to find any examples.

Share this post


Link to post
Share on other sites
In practice, two issues exist.

#1: Given a triangle with 3 vertices, each with position and texture coordinates, algorithms like the referenced webpage generate reasonable tangent/bitangent vectors.

#2: In practice, most 3D objects are smooth shaded, which means most vertices are shared by 3 to many triangles. The computation of normal/tangent/bitangent for a vertex will usually be different for each of the triangles that includes that vertex.

To make the object shade and bumpmap correctly, all the computed normal/tangent/bitangent vectors for a given vertex need to be averaged together to produce a good averaged value. If you do not do this, if you choose the values from only one of the triangles, your shading and bumpmapping will be less than optimal.

Be careful though! Two traps are waiting to snare you!

A: Your code will not generate the best average values unless you weight the contributions of each set of values by the angle (of the triangle) at that vertex. In other words, compute the unit normal/tangent/bitangent vectors, then multiply them by the angle at that vertex, and add them to three accumulating "average" vectors. When your code has computed the vectors for all triangles that share the vertex, just normalize those accumulating average vectors to produce the unit vectors your software needs.

B: When you perform the process described in A above, make sure it does NOT include any triangles that are not smooth shaded at that point. Depending upon how your applications organizes vertices, this may or may not require your code to check for this problem. To understand the problem, consider a cylinder with a flat bottom surface that closes the cylinder (and makes it a cup with a bottom surface). A vertex at the bottom of the cylinder might be shared with the flat bottom surface in some applications, but not others. Clearly the side of the cylinder is NOT smooth-shared onto the flat bottom surface - this is a sharp edge! If this vertex IS shared in your model/software, you must assure its normal/tangent/bitangent vectors are NOT averaged into the vertex for rendering the sidewall of the cylinder. And likewise, the vectors of the triangles on the sidewall of the cylinder must not be averaged with the vertex on the bottom surface when rendering the flat bottom surface. This is a BIG problem for some (minority) of models and software, because totally two massively different normal/tangent/bitangent vectors are required for this one shared vertex. The majority of models will have two vertices at this location - one for the cylinder sidewall, and another for the flat bottom surface.

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