Object2World and World2Object Matrices

Hi all.

Is the _Object2World Matrix Orthogonal ? I mean , Is the Inverse Transpose of _Object2World is equal to _Object2World Matrix ? , Is it true that :

_Object2World  = Inverse Transpose  (_Object2World ) //is orthogonal ?

I had test these two last lines of shaders for normal’s vector transformation and I had got same result : ( one of them has been commented, and also both of them works correct.)

     V2F vertexProgram(vertexInput input)
      {
       V2F output;
    
       float4x4 modelMatrix = _Object2World;
       float4x4 modelMatrixInverse = _World2Object; 
       float4x4 modelMatrixInverseTranspose = transpose(modelMatrixInverse);
    
       output.viewDir = float3(mul(modelMatrix, input.vertex) -
              float4(_WorldSpaceCameraPos, 1.0));
    

        //****THESE TWO LINES GIVE SAME RESULT.***// 
    
        //output.normalDir = mul(_Object2World,float4(input.normal,0));
    
        output.normalDir = mul(modelMatrixInverseTranspose,float4(input.normal,0));
      }

Because both of the below lines works correct, I had concluded that the _Object2World is an orthogonal matrix.

    output.normalDir = mul(_Object2World,float4(input.normal,0));
        
    output.normalDir = mul(modelMatrixInverseTranspose,float4(input.normal,0));

Am I going wrong ?

Thanks in advance.

There is no 100% need for _Object2World to be orthogonal, but as it is normally based on position, rotation and scale in Unity, it is indeed orthogonal. So Unity provides an orthogonal _Object2World to shaders.

For normals you can actually use a multiplication with a 3x3 matrix, since the position can be skipped:

 output.normalDir = mul((float3x3)_Object2World, input.normal);

Thanks . So _Object2World is orthogonal in shaders .

As far as I know, Unity doesn’t include scale in its transformation matrices. This means that the top-left 3x3 submatrix of _Object2World and _World2Object will always be orthogonal in Unity, which of course means that transpose(inverse(MV)) == MV.

This is what you want for normals, but unlike what jvo3dc says, _Object2World and _World2Object are not orthogonal if you use translation.

In general, a transformation matrix is only orthogonal if it does not include scaling or translation. Only mirroring and rotation are orthogonal transformations.