# World space to tangent space

This topic is 2783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

 // Normalize the light and view vectors and transform it to the tangent space: float3x3 mWorldToTangent = float3x3( vTangentWS, vBinormalWS, vNormalWS ); // Propagate the view and the light vectors (in tangent space): Out.vViewTS = mul( mWorldToTangent, vViewWS ); Out.vLightTS = mul( vLightWS, mWorldToTangent ); 

vLightWS, vViewWS is the lgith vector and view vector in world space.

My question is that the last two line codes are doing the same operation but with inverse order to multiply matrix. I think the last is wrong, but the program runs well. Why?

##### Share on other sites
What can you say about a float3? Is it a 3x1 or 1x3 matrix?

I think that "mul" function deals with that difference.

##### Share on other sites
Thank you, programci_84.
But i dont get it.

I think the variable "mWorldToTangent" may be not right if it will be used to multiply a vector at the right side of mul function.
Because mul() function give different result according to the position of params.

We can see [color="#000000"]mul[color="#666600"]([color="#000000"] mWorldToTangent[color="#666600"],[color="#000000"] vViewWS ) != m( vViewWS, mWorldToTangent ).

So the last codes is not right, isn't it?

##### Share on other sites
[font=courier new,courier,monospace]Out.vLightTS = mul( vLightWS, mWorldToTangent );[/font]
is the same as
[font=courier new,courier,monospace]Out.vLightTS = mul( transpose(mWorldToTangent), vLightWS );[/font]
and in the case of pure 3x3 rotation matrices
[font=courier new,courier,monospace]transpose(rotation) == inverse(rotation)[/font]

So what that code is doing is multiplying by the inverse of that rotation matrix.

If [font=courier new,courier,monospace]vLightWS[/font] and [font=courier new,courier,monospace]vViewWS[/font] are both in world-space, then yes, the code looks fishy, as one is being transformed by a TBN rotation and one by the inverse...

##### Share on other sites
Yes, Hodgman.

So the last codes ---[color="#660066"]Out[color="#666600"].[color="#000000"]vLightTS [color="#666600"]=[color="#000000"] mul[color="#666600"]([color="#000000"] vLightWS[color="#666600"],[color="#000000"] mWorldToTangent [color="#666600"]), is wrong? Do you think so?

But the program runs well with the last code. Why? Who can tell me?

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 43
• 75