Jump to content
  • Advertisement
Sign in to follow this  

How can compute tangent vector like D3DXComputeTangentFrame

This topic is 5165 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

Hi all. Im writing engine for load Quake3 Map with suport pixel light in DirectX So i cant use D3DXComputeTangentFrame function for compute tangent for my maps's vertices. I ve read article by Jakob Gath [http://www.blacksmith-studios.dk/projects/downloads/tangent_matrix_derivation.php] but i ve some problem. - fomula form that site is show how to compute tangent for 1 triangle (3 Vertex) data. But if some vertex share in another triangle. How to do ? Quake3 arrange vertices as a triangle fan so must have share vertex. - What's happen if determinant be "0" - and this is my fuction for compute tangent, It not work, what wrong T_T

D3DXVECTOR3 v2v1 = V2.pos - V1.pos;
D3DXVECTOR3 v3v1 = V3.pos - V1.pos;

// Calculate c2c1_T and c2c1_B
float c2c1_T = V2.TexCoord.u - V1.TexCoord.u;
float c2c1_B = V2.TexCoord.v - V1.TexCoord.v;

// Calculate c3c1_T and c3c1_B
float c3c1_T = V3.TexCoord.u - V1.TexCoord.u;
float c3c1_B = V3.TexCoord.v - V1.TexCoord.v;

float fDeterminant = c2c1_T * c3c1_B - c3c1_T * c2c1_B;
if (fabs(fDeterminant )< EPSILON) // avoid divsion by zero.
	Tangent		= D3DXVECTOR3( 1.0f, 0.0f, 0.0f );
	BiNormal	= D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	Tangent	= D3DXVECTOR3((c3c1_B * v2v1.x - c2c1_B * v3v1.x),
		   	      (c3c1_B * v2v1.y - c2c1_B * v3v1.y),
			      (c3c1_B * v2v1.z - c2c1_B * v3v1.z));

	BiNormal = D3DXVECTOR3((-c3c1_T * v2v1.x + c2c1_T * v3v1.x),
			       (-c3c1_T * v2v1.y + c2c1_T * v3v1.y),
			       (-c3c1_T * v2v1.z + c2c1_T * v3v1.z));

	Tangent	  *= 1.0f/fDeterminant;
	BiNormal  *= 1.0f/fDeterminant;

thx a lot for reply

Share this post

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

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!