# calculating normal/tangent vector

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

## 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 on other sites
can someone give any hint? :(

##### Share on other sites
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 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 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.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633388
• Total Posts
3011617
• ### Who's Online (See full list)

There are no registered users currently online

×