Compute Tangent

Started by
10 comments, last by maxgpgpu 14 years, 10 months ago
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.

Advertisement
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.

This topic is closed to new replies.

Advertisement