godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.93k stars 3.21k forks source link

Shader matrix column/row major ordering very unclear #9616

Closed CodeSmith32 closed 2 weeks ago

CodeSmith32 commented 3 months ago

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 commented 3 months ago

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.

AThousandShips commented 3 months ago

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

Flarkk commented 2 months ago

Duplicate of #5805