Jump to content
  • Advertisement
Sign in to follow this  
grunt123

calculating normal/tangent vector

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a primitive rendered in immediated mode, and diffuse texture and normal texture for it. Anyone knows how to calculate normal/tangent vector for each vertex of the primitive?

Share this post


Link to post
Share on other sites
Advertisement
Well, there's a few steps to that. Since you're talking per-vertex, I won't discuss the "normal texture", which is a separate step which only makes sense once you have normal/tangent/bitangent for each vertex.

So. For normals, if they aren't built into the vertex data (they really should be, if you have a normal texture), you'll need to interpolate them from the surrounding faces. Tell me if you actually need to do this; it is EXTREMELY strange that you would have a normal texture but no vertex normals.

Now, for tangents and bitangents (often incorrectly termed binormals). The general convention is that the tangent vector is in the same plane as the u coordinate of the texture mapping, and is perpendicular to the normal vector. Once you have that, the bitangent is simply the cross product of the normal and the tangent (or the other way around, depending on your handedness).

This is all just an overview, though. There's some decently heavy linear algebra involved, especially in the tangent computation, and packages such as DirectX provide utility functions for calculating it. Do some more research on each of these steps, and post again if there's anything you absolutely can't figure out.

Share this post


Link to post
Share on other sites
well, since i'm redering in immediate mode and setting vertex data myself, i guess that i have to specify normal vector for each vertex then?

Share this post


Link to post
Share on other sites

Usually when you have a normal map your mesh has three vectors associated at each vertex: normal, tangent, bitangent. These three vectors form a basis (a coordinates system) in which the light vector, once it is in object space, can be transformed into tangent space, interpolated across vertices within the pixel shader and used for lighting in conjunction with the normal map.

If you have a texture mesh without the tangent space basis set at each vertex you can reconstruct the tangent space basis given the texture coordinates and the object coordinates of each vertex.

This is going to give you more than you want to know but here it is anyway.

www.umr.edu/~kwoxrf/

Right click and "save target as" "Real-Time Lighting and Shadowing.doc" Read the section under the heading "The Tangent Space Calculation" If you have more questions I suggest reading the entire paper, skipping the stuff about shadow volumes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!