Archived

This topic is now archived and is closed to further replies.

Bobby-D

Generating texture space

Recommended Posts

Bobby-D    122
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.

Share this post


Link to post
Share on other sites
Nekhmet    132
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.


Share this post


Link to post
Share on other sites
Bobby-D    122
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????

Share this post


Link to post
Share on other sites