walbourn/directx-sdk-samples

Transforming Normal Vectors

matt77hias opened this issue · 2 comments

Applying a transformation M to both a surface and a surface tangent, results in a transformed tangent of the transformed surface. Applying a transformation M to both a surface and a surface normal, does not necessarily result in the transformed normal of the transformed surface. To obtain the transformed normal, one should use a transformation N=(M^-1)^T (i.e. transposed inverse of the original transformation matrix M).

Shouldn't this matrix N be used instead of M in for example directx-sdk-samples/Direct3D11Tutorials/Tutorial06/Tutorial06.fx?

If the matrix contains only rotations, then a transposed inverse is the original matrix.

The tutorial is quite basic, and you are correct that a more sophisticated shader would use a WorldInverseTranspose (such as is done in the BasicEffect shaders for DirectX Tool Kit).

You're correct in the current setup (orthogonal matrix' transpose is equal to inverse):
g_World = XMMatrixRotationY( t );

I just mentioned this for more generality (couldn't add the label "enhancement" myself) since Render is likely the method people want to change and experiment with.