Sign in to follow this  

Convert vector to tangent space

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

Hello. Recently I implemented normal mapping and it works:
[url="http://volgogradetzzz.blogspot.com/2012/06/normal-mapping.html#more"]http://volgogradetzzz.blogspot.com/2012/06/normal-mapping.html#more[/url]

But althought I did it by myself some things not clear. Here's the vertex shader code:

[CODE]
worldPosition = mul4x4(pos, MODEL_MATRIX); // vertex position in world sopace
lightDistance = LIGHT_WORLD_POSTION - worldPosition; // vertex-light distance in world space

op = mul4x4(worldPosition, PROJECTION_MATRIX);

lightDistanceOut.w = ZERO_VECTOR;

tangentModel = mul4x4(tangent, ROTATION_MATRIX); // vertex tangent in world space
dp3 lightDistanceOut.x, lightDistance, tangentModel; // ??????????????

normalModel = mul4x4(normal, ROTATION_MATRIX); // vertex normal in world space
dp3 lightDistanceOut.z, lightDistance, normalModel; // ??????????????

crs binormalModel.xyz, normalModel, tangentModel; // vertex binormal in world space
dp3 lightDistanceOut.y, lightDistance.xyz, binormalModel.xyz; // ??????????????[/CODE]
This code convert vector to light to tangent space. My questions are:
1. Initialy I have tangent and normal in model space and first of all I convert them to world space by multiplying by model's rotation matrix. Is it correct?
2. Now, when I have T, B, N vectors in world space (is it in world or maybe I'm wrong?) I can construct matrix with rows as T, B, N vectors. But If I multiply vector to light by that matrix I get incorrect results. And in code above all this dot products is just shortcut for multiplication by matrix rows, not by columns (i.e. by inverse/transpose of my TBN matrix) - and it works. But why?

Share this post


Link to post
Share on other sites
This looks wrong:

[source lang="c"]lightDistanceOut.w = ZERO_VECTOR;[/source]


Assuming w is a scalar component should not this be

[source lang="c"]lightDistanceOut.w = 0.0;[/source]

alternatively

[source lang="c"]lightDistanceOut = ZERO_VECTOR;[/source]

? Edited by Xashmi

Share this post


Link to post
Share on other sites

This topic is 2012 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.

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