nikoniko

06-24-2017, 08:08 PM

I am a bit confused about matrices and matrix multiplication in GLSL. It is not clear to me where the entries go.

Let's say I have a vec2 v = vec2(1.0f, 2.0f); and a matrix mat2 m = mat2(1.0f, 2.0f, 0.0f, 1.0f); I can multiply those two together v = m * v;

I think GLSL interprets vectors as column vectors, which means that the matrices are filled column after column. So the multiplication above is actually 2402. Also, this means that a mat2x3 is actually would appear as a 3x2 matrix in linear algebra, and can be multiplied from the left by a vec2.

Edit: Moreover, we can multiply matnxm times matkxn, in that order.

Is this the right interpretation?

Let's say I have a vec2 v = vec2(1.0f, 2.0f); and a matrix mat2 m = mat2(1.0f, 2.0f, 0.0f, 1.0f); I can multiply those two together v = m * v;

I think GLSL interprets vectors as column vectors, which means that the matrices are filled column after column. So the multiplication above is actually 2402. Also, this means that a mat2x3 is actually would appear as a 3x2 matrix in linear algebra, and can be multiplied from the left by a vec2.

Edit: Moreover, we can multiply matnxm times matkxn, in that order.

Is this the right interpretation?