Rotating Tangent Matrix

Started by
1 comment, last by NiteLordz 16 years, 5 months ago
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
Code makes the man
Advertisement
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.
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
Code makes the man

This topic is closed to new replies.

Advertisement