Sign in to follow this  
NiteLordz

Rotating Tangent Matrix

Recommended Posts

NiteLordz    808
i am setting up my level, the next phase of my project and i have created my objects in 3d studio max, and have successfully imported them into my level editor, and then into my engine. now i have encountered a problem and and not sure how to handle it. when i load in the models, i create a tangent matrix for the models, and that is in the local coorinate system. now i place my models into the level, and using dynamic lights, i am getting improper lighting ( if i rotate the object, the light is lighting the wrong side of the models, because teh tangent matrix is computed for the local system, and not for it's place in the world. i am unsure of how to handle computing the tangent matrix in the gpu for a rotating matrix such that the lighting is proper. currently in my shader i compute the tangent vectors as such Out.lightVec.x = dot( lightVec, tangent ); Out.lightVec.y = dot( lightVec, binormal ); Out.lightVec.z = dot( lightVec, normal ); i am assuming that i have to do a few more things to place them into the world position. thanks for any help guys

Share this post


Link to post
Share on other sites
yahastu    154
If your tangent are proper in object space, all you need to do is pre multiply it by the world matrix. you only need the rotation part but the translations wont hurt it.

Share this post


Link to post
Share on other sites
NiteLordz    808
can you help me out with maybe a snippet of code. i am playing around with it here, and i can not get it right. not sure if i am transforming from world to tangent before or after.

// in the lighting shader
float4x4 matMVP;

// New Way
float3x3 matTBN = float3x3( tangent, binormal, normal );

// Old Way
Out.lightVec.x = dot( lightVec, tangent );
Out.lightVec.y = dot( lightVec, binormal );
Out.lightVec.z = dot( lightVec, normal );

i am not sure what i am supposed to do now.

thanks for your help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this