1

Initially I thought it just means that the last column is simply discarded, but apparently I am getting differing results when I do such conversion as contrasted with just declaring a 3x2 matrix.

float3x3 TBN = float3x3(IN.tangent, IN.binormal, IN.normal);
float3x2 TB  = float3x2(IN.tangent, IN.binormal);

half2 vNormalTBN = mul(sampledNormal, (float3x2)TBN);
half2 vNormalTB  = mul(sampledNormal, TB);

1 Answers1

1

I'm absolutely no shader expert so this is just a very wild guess and might be completely wrong! ^^

Afaik the components in the matrix are layed out column wise (vertically) and look somewhat like

IN.tangent.x IN.binormal.x IN.normal.x
IN.tangent.y IN.binormal.y IN.normal.y
IN.tangent.z IN.binormal.z IN.normal.z

and is memory wise simply stored as 9 floats in this order.

So similar when you explicitely use the float3x2 constructor you get something like

IN.tangent.x IN.binormal.x
IN.tangent.y IN.binormal.y
IN.tangent.z IN.binormal.z

When however you simply typecast I suspect that you simply cut off the last 3 float values and force the shader to interpret this now 6 floats array as a new float3x2 matrix which now might look like

IN.tangent.x  IN.binormal.x
IN.normal.x   IN.tangent.y
IN.binormal.y IN.normal.y
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • Oh, thank you for your answer, that makes sense but it is really bewildering what would be the possible use for such a mixed up matrix. The context of my question was a reverse engineered moon shader from the Witcher 3 game as described [on the following blog here](https://astralcode.blogspot.com/2018/12/reverse-engineering-rendering-of_22.html?fbclid=IwAR0G-PbM8lpCVG56aKABtQnQYJMzMFDmn-CwFNNUwMTDVSF3NzXB-b-xun0) in the section where the world-space TBN matrix is cast into such 3x2 matrix. – Maria Heine Jul 31 '20 at 10:47
  • I don't know as said this is just a wild guess ... and if it is true there is absolutely no use ^^ you just should not use the cast then – derHugo Jul 31 '20 at 11:41