GLSL is OpenGL's shader language.
webGPU is coming up with its own shader language, but as of this writing (Oct 13, 2020), the shader language it uses is SPIR-V, which can be cross-compiled from GLSL pretty well.
OpenGL and, by extension, its shading language GLSL, use a column-order mapping for its matrices, e.g.,
By contrast, my game engine Grimoire utilizes row-order mapping for its matrix,
A matrix in column order:
- has its translation components in the 4th column.
- has its rotational components along the x-, y-, and z-axes in the first, second, and third columns respectively.
A matrix in row order:
- has its translation components in the 4th row.
- has its rotational components along the x-, y-, and z-axes in the first, second, and third rows respectively.
Luckily, when Grimoire lays out its
Matrix44 sequentially in memory as a 1-dimensional array, when GLSL reads and instantiates the memory data into its
mat4 object, it correctly places the components in its necessary locations.
|1D Array Index||0||1||2||3||4||5||6||7||8||9||10||11||12||13||14||15|
From the table above, you can see that the translation components of a
Matrix44, located at
m32, will be placed in the 1D array at indices 12, 13, and 14, respectively.
When GLSL reads the 1D array, it'll take the data at indices 12, 13, and 14, and place them correctly in the 4th column, at
In GLSL, multiplication between two
mat4s work as you would expect. The left-hand
mat4's rows are cross-multiplied against the right-hand
mat4's columns to generate another
Also, as you would expect, matrix multiplication is NOT commutative.
Ma * Mb != Mb * Ma.