Jump to content
  • Advertisement
Sign in to follow this  
Godlike

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.

If you intended to correct an error in the post then please contact us.

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;

}
Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!