godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Shader matrix column/row major ordering very unclear

Open CodeSmith32 opened this issue 1 year ago • 3 comments

Your Godot version:

Godot v4.2.2

Issue description:

The Godot shader language documentation for matrix column- vs. row-major ordering is very unclear:

  1. There is no specification as to whether matx( vecx, vecx... ) constructor form is column- or row- major.
  2. The documentation states that matrix index access is row-major (i.e. matrix[2] is a row not a column) which completely diverts from GLSL, and also seems like a terrible decision since two-dimensional array access is column-major (matrix[2][1] is the 2nd column, then the 1st row). Is this true? Or is it a documentation discrepancy?

URL to the documentation page:

Live documentation: https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/shading_language.html#members

GitHub file: https://github.com/godotengine/godot-docs/blob/4.2/tutorials/shaders/shader_reference/shading_language.rst?plain=1#L112

CodeSmith32 avatar Jul 17 '24 03:07 CodeSmith32

FWIW, with some experimentation (but not with certainty), constructor ordering seems to be column-major. i.e., mat3(vec3, vec3, vec3) seems to be vectors of columns, not rows.

CodeSmith32 avatar Jul 17 '24 03:07 CodeSmith32

It describes that they are column major, but it's contradictory in the second clause:

For matrices, use the m[column][row] indexing syntax to access each scalar

And

or m[idx] to access a vector by row index.

So generally it's stated to be column major, which is to match GDScript I assume

But some more clarification would be good

AThousandShips avatar Jul 17 '24 15:07 AThousandShips

Duplicate of #5805

Flarkk avatar Sep 06 '24 18:09 Flarkk