# Thread: I am a bit confused about GLSL matrix multiplication.

1. ## I am a bit confused about GLSL matrix multiplication.

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 . 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?

2. Originally Posted by nikoniko
I think GLSL interprets vectors as column vectors, which means that the matrices are filled column after column. So the multiplication above is actually .
Correct. Matrix constructor arguments are in column-major order.
Originally Posted by nikoniko
Also, this means that a mat2x3 is actually would appear as a 3x2 matrix in linear algebra,
Correct. GLSL terminology is backwards; matMxN has M columns and N rows, whereas long-standing mathematical convention is that a "M × N" or "M by N" matrix has M rows and N columns.
Originally Posted by nikoniko
and can be multiplied from the left by a vec2.
Correct. A matrix-vector multiplication can have the vector on either side; it will be treated as a row vector if it's on the left and a column vector if it's on the right.
Originally Posted by nikoniko
Edit: Moreover, we can multiply matnxm times matkxn, in that order.
Correct.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•