I was wondering if the both shader codes are equivalent. So the question is, is this GLSL

vNormal = mat3(FUSEE_ITMV[0].xyz, FUSEE_ITMV[1].xyz, FUSEE_ITMV[2].xyz) * fuNormal;

Equivalent to this HLSL?

float3x3 fMatrix = {FUSEE_ITMV[0].xyz,FUSEE_ITMV[1].xyz,FUSEE_ITMV[2].xyz};
output.normal = normalize(mul(input.normal,(float3x3)fMatrix));

Theoretical I'd say yes they are but I'm not sure. Can anyone verify that they are equivalent?


1 Answer 1


Yes, assuming your FUSEE_ITMV matrix in HLSL is the transpose of the FUSEE_ITMV GLSL matrix, otherwise you need to make sure it's transposed. GLSL mat3 deals with the passed vectors as columns of the matrix. HLSL float3x3 on the other hand deals with them as rows.


mat3 m( column0, column1, column2);
m[0]; // returs the first column


float3x3 m = float3x3(row0, row1, row2); // sets rows of matrix n
m[0]; // Returns first row.

As far as you are indexing you matrices in a uniform way, columns for columns and rows for rows, this will assign each column to its equivalent column in the glsl mat3 and each row to its equivalent row in the glsl float3x3

  • \$\begingroup\$ No my HLSL FUSEE_ITMV isn't the transposed to the FUSEE_ITMV from GLSL. I'm transposing the one from HLSL within my Engine before I render my frame, so after I created my InputLayout. Could these lead to another rendering? \$\endgroup\$
    – Rey
    Nov 18, 2013 at 15:36
  • \$\begingroup\$ I don't know about how you are doing it in your code, but as long as your GLSL is being passed a column matrix and your HLSL a row matrix, they are the same. In other words every column in GLSL matrix should be equivalent to every row in the same HLSL matrix. \$\endgroup\$
    – concept3d
    Nov 18, 2013 at 16:00
  • \$\begingroup\$ @Rey I hope it worked! \$\endgroup\$
    – concept3d
    Nov 18, 2013 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .