Tangents for Mesh not Calculated Correctly?

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

Recommended Posts

I'm trying to implement normal mapping but I've been having some trouble calculating the tangents for my model. I'm loading in from an .obj exported from blender if that makes any difference. For each triangle (not currently using VBO indexing although I am averaging the tangents properly) I runt he following calculations to calculate the tangent:

glm::vec3 edge1 = _verts[vi.y] - _verts[vi.x];
glm::vec3 edge2 = _verts[vi.z] - _verts[vi.x];

glm::vec2 d_UV1 = _tex_coords[ti.y] - _tex_coords[ti.x];
glm::vec2 d_UV2 = _tex_coords[ti.z] - _tex_coords[ti.x];

float f = 1.0f / (d_UV1.x * d_UV2.y - d_UV1.y * d_UV2.x);

glm::vec3 tangent = glm::normalize((edge1 * d_UV2.y - edge2 * d_UV1.y) * f);

Where vi is a vector3 containing the indices of the 3 vertices and ti is also a vector3 containing the indices of the texture coordinates. I based the code off of here: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/. When I try visualizing the tangents in the shader, all I am seeing is black on a cube, whereas the normal are showing color and when I make a TBN matrix and when I use a blank normal map I get some odd results that are not the same as the regular normals, even though in theory they should be. Any ideas?

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 33
• 16
• 11
• 10
• Forum Statistics

• Total Topics
634123
• Total Posts
3015629
×