# [Gtkradiant] [Bug 629] Bumpmapping: proper tangent vector code

**gtkradiant@zerowing.idsoftware.com
**
gtkradiant@zerowing.idsoftware.com

*Sun, 20 Oct 2002 18:38:27 -0500*

http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=629
ydnar@shaderlab.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
------- Additional Comments From ydnar@shaderlab.com 2002-10-20 18:38 -------
http://shaderlab.com/q3map2/screenshots/bumpmapping_works.jpg
Calculated per-vertex, per-triangle. Haven't seen the formula I used documented
anywhere, so I'll do so here.
For every triangle, every vertex, you need to compute 2 tangent vectors in
order for normalmapping to work correctly. They translate from ST shifts to
world space.
Take vertex ST coordinate. Shift by desired amount (texture space) Calculate
barycentric coordinates of new ST coordinate. Use the barycentric coordinates
(triangle space) to calculate XYZ coordinate (world space). Subtract original
vertex XYZ coordinate and normalize.
Todo:
- Deal with phong shading a bit better, as current tangent vectors lie in each
triangle's plane, rather than being perpendicular to the interpolated normal at
the sample point
- Interpolate the modified tangent vectors when subdividing the triangle