# headache: tangent space normal mapping

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

## Recommended Posts

Ive been trying for some time now to crate a glsl shader for tangent space normal mapping. Unfortunately despite my efforts I couldn't find a viable solution. In the above pic the right mesh appears correctly but the cube not. So I want to ask if the face tangents are incorrect or something. In the cube the bumps are facing out of the cube center. The tiny vectors are the blue for normal, red for tangent and green for bitangent. Pic: Code for calculating the tangents:
for( unsigned int i=0; i<tris_num; i++ )
{
const triangle_t& tri = tris;
const int vi0 = tri.vert_ids[0];
const int vi1 = tri.vert_ids[1];
const int vi2 = tri.vert_ids[2];
const vec3_t& v0 = verts[ vi0 ].coords;
const vec3_t& v1 = verts[ vi1 ].coords;
const vec3_t& v2 = verts[ vi2 ].coords;
vec3_t edge01 = v1 - v0;
vec3_t edge02 = v2 - v0;
vec2_t uvedge01 = uvs[vi1] - uvs[vi0];
vec2_t uvedge02 = uvs[vi2] - uvs[vi0];

float det = (uvedge01.Y * uvedge02.X) - (uvedge01.X * uvedge02.Y);
DEBUG_ERR( IsZero(det) );
det = 1.0f / det;

vec3_t t = ( edge02 * uvedge01.Y - edge01 * uvedge02.Y ) * det;
vec3_t b = ( edge02 * uvedge01.X - edge01 * uvedge02.X ) * det;

t.Normalize();
b.Normalize();

face_tangents = t;
face_bitangents = b;

}

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

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

• Total Topics
633387
• Total Posts
3011609
• ### Who's Online (See full list)

There are no registered users currently online

×