Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

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

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2017
    Posts
    5

    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 Click image for larger version. 

Name:	CodeCogsEqn.gif 
Views:	20 
Size:	1.4 KB 
ID:	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?
    Last edited by nikoniko; 06-24-2017 at 08:15 PM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,411
    Quote Originally Posted by nikoniko View Post
    I think GLSL interprets vectors as column vectors, which means that the matrices are filled column after column. So the multiplication above is actually Click image for larger version. 

Name:	CodeCogsEqn.gif 
Views:	20 
Size:	1.4 KB 
ID:	2402.
    Correct. Matrix constructor arguments are in column-major order.
    Quote Originally Posted by nikoniko View Post
    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.
    Quote Originally Posted by nikoniko View Post
    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.
    Quote Originally Posted by nikoniko View Post
    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
  •