Calculating Tangent vectors for Normal Bump Mapping...help again!!

This topic is 4955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I'm trying to add local normalmaping for Torque game engine's interior rendering core. But no matter what I tried, I can't get the tangent vectors right for them. Here is what I did from the start: -I have read these articles: * Derivation of the Tangent Space Matrix This one really helped to understand the concept... * Derivation Computing tangent space basis vectors for an arbitrary mesh This one confused me...what is handedness? w component to the tangent vector?? why single tangent vector array???...etc -When I applied the process in link-1, I noticed the tangent vectors aren't in form they supposed to be... some normals were looking inside the polygons, some where away... It seems I have been facing the problem mentioned in NVidia article's about per pixel lighting... It says tangent and binormal vectors needs to be well-behaved from vertex to vertex... I think this is my problem... How can I solve this?? Any help is appreciated, Thanks

Share on other sites
You only need to store a single tangent array because the normal, tangent and bitangent (binormal) are all perpendicular to each other. Therefore, if you have two of them you can always regenerate the third using a cross-product (two instructions in a vertex shader).

However, depending on your data, cross(normal, tangent) may sometimes give the a vector pointing in the opposite direction of the bitangent. The "calculate handedness" code at the end of 2) checks for this. A more verbose version of the code would look something like:

if (dot(cross(normal,tangent),bitangent) < 0.0f)
{
tangent.w = -1.0f
}
else
{
tangent.w = 1.0f
}

The idea is that in the shader you will do something like

bitangent = cross(normal, tangent.xyz)*tangent.w;

That way if the cross product gives the wrong result, the multiply corrects it.

What is handedness?
Make a finger-gun with your right hand by pointing your first finger out and with your thumb pointing up. Now stick your middle finger out (pointing to the left). See how your fingers are all perpendicular to each other? Kinda like the X,Y and Z vectors of an identity matrix, eh? Now do the same thing with your left hand. Now you've got a matrix that is a mirror image of the one in your right hand. Both are perfectly valid sets of basis vectors to use to define a coordinate frame. Therefore, when you are working with a transformation matrix it is important to know if the matrix's basis vector point like your left hand or your right hand. Different systems use different standards. With tangent spaces, the handedness of a face's tangent frame is based on whether the artist used a clockwise or counterclockwise UV layout.

Share on other sites

Basically, the *reason* we have handedness problems is that sometimes, artists apply the texture face-up, and sometimes, they mirror it. Mirroring is useful, but it makes tangent-space computation harder.

Go to this web-page:

http://www-2.cs.cmu.edu/~jkh/video_games/schedule.html

And download the bumpmapping lecture. Take a look at slides 10-12. See how I drew a +S and a +T vector onto the texture itself? Those are the tangent and the binormal. Now, if I apply the texture flat onto a polygon, then it's obvious which way the tangent and the binormal go. If I warp the texture a little, then you have to fudge the tangent and binormal a little. But if I mirror the texture, then there's nothing you can do - there is no "correct" direction for the tangent. The only solution is to split the mesh along the mirror line, so that now it's two separate meshes, with no mirroring.

The basic rule is this: if one polygon has the texture "face-up", and another texture has the texture "face-down", then those two polygons may not be part of the same mesh.

- Josh Yelon
-- Distribution Maintainer, Panda3D

Share on other sites
http://www.terathon.com/code/tangent.html helped me :)

Share on other sites

Thank you very much Josh!

I'd guessed the problem was all about texturing...
You really helped me clear the things up :)

Galip

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×