Skip to main content
gamedev.net
🔒 Locked

Generating texture space

Started by Bobby-D Aug 15, 2003 at 3:00 AM 2 replies 600+ views
Original Post
Bobby-D
Bobby-D
In order to write any form of perpixel bump mapping shader, I need a fast way to transform a normal or vector into texture space. Can anyone out there tell me how to do this. Is there a way I could generat a texture space matrix quickly at run time? One by one, the peguins steal my sanity.
One by one, the peguins steal my sanity.
Nekhmet
Nekhmet
Computing texture space is a big project.

Generally, you do this in a few steps:

1. When you load the model, you assign each vertex a "tangent" and "binormal" vector. Basically, these are two vectors that lie flat against the skin of the model. The tangent points toward the "top" of the texture, and the binormal points toward the "right" of the texture. Of course, since textures can be applied in pretty distorted ways, there''s no "true" answer. However, if you come up with a reasonable technique for approximating which way is up, it''ll probably work fine.

2. Suppose, hypothetically, that a texture is mirrored on your model. In that case, the "right" side of the texture is actually in *two directions*. In these situations, it is impossible to compute a tangent and binormal. So you have to detect this situation and alter the geometry of the model at load time to eliminate this case.

3. When you deform the model, say, using a bone-based animation system, you have to deform the tangents and binormals too. This is pretty straightforward, you just use the same code to deform the tangents and binormals as you do for the normals.

4. Finally, when it comes time to render, the normal, binormal, and tangent form a coordinate system. This is the "texture space" coordinate system you need. Using a few dot-products, you can transform the light into this coordinate system. Of course, that''s the easy part... steps 1-3 are the hard ones.


Bobby-D
Bobby-D
Thanx. That''s rather helpful, but i''m very stuck at step one...Generating the Tangent and Binormal (I''ve got the rest figured out.) If I pass the three vert of a triangle along with the three texture coordinates into a function, the Normal is simply the cross product of two edges, but how do I calculate the other two vectors????
One by one, the peguins steal my sanity.
bakery2k1
bakery2k1
See the addendum to my tutorial at www.paulsprojects.net for a function to calculate the tangent vectors.

[edited by - bakery2k1 on August 16, 2003 4:26:06 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.