Passing mat3 or mat4 as a shader parameter.
Asked Answered
T

6

0

Hello!
If I do this:

uniform mat3 R;
void vertex()
{
    VERTEX = R * VERTEX;
}

The mesh disappears even though matrix R (when visualized in shader paramerers section) is identity matrix. So it shouldn't modify VERTEX.

And when I do this:

uniform mat4 R;
void vertex()
{
    VERTEX = (R * vec4(VERTEX, 0.0) ).xyz;
}

It is the same effect. The mesh disappears.

Also, the mat4 data type is visualized in the editor not as 4x4 but as 4x3 matrix. And this is not quite clear. We cannot multiply 4x3 by 4x1. Is what we see in the editor properties is actually 4x3 transposed?

Why does a mesh disappear after VERTEX = R * VERTEX with R being identity matrix?

Tsar answered 8/11, 2022 at 17:52 Comment(0)
N
0

So Godot does not have a 4x4 matrix class, and I don't think you can pass arbitrary values and have then interpreted as a matrix by the shader.

You can use the Transform class (or R would be a Transform) and this will be a 4x3 matrix in the shader uniform (I believe mat4 with the extra values as zero).

See here: https://github.com/godotengine/godot-proposals/issues/258

Nottage answered 8/11, 2022 at 18:5 Comment(0)
T
0

Nottage So Godot does not have a 4x4 matrix class

Assuming that mat4 is not 4x4 but something else vector = matrix * vector is
(4x1) = (Na x Nb) * (4x1)
Then what can "Na" and "Nb" be? How does the inner product work at all in shaders?
You are saying Na=4 and Nb=3. But in matrix multiplication inner product require inner dimensions to be the same. No?

For some reason each time I click "Edit" button, the web site multiplies my message 🙂

Also this is what is written in Godot documentation here https://docs.godotengine.org/en/3.0/tutorials/shading/shading_language.html#data-types: "mat4 4x4 matrix, in column major order."

Tsar answered 8/11, 2022 at 20:12 Comment(0)
H
0

Nottage So Godot does not have a 4x4 matrix class, and I don't think you can pass arbitrary values and have then interpreted as a matrix by the shader.

As per your link there is now a Projection built-in class which is a 4x4 matrix.

https://github.com/godotengine/godot/pull/63219

Hypodermis answered 8/11, 2022 at 20:13 Comment(0)
N
0

Hypodermis As per your link there is now a Projection built-in class which is a 4x4 matrix.

In Godot 4.0 yes, I assumed the OP was using 3.x.

Nottage answered 8/11, 2022 at 21:0 Comment(0)
N
0

Yes, the Godot shading language uses matrices and has mat4. What I meant in GDScript for passing custom matrices. But you can do this with Transform.

Transform is technically 4x3, meaning it only supports rotation, scale, and translation, but will become a mat4 when passed as a uniform.

However, this won't work for real 4x4 matrices, like if you wanted a custom camera projections, which is why the Projection class was added in Godot 4.0.

Nottage answered 8/11, 2022 at 21:3 Comment(0)
A
0

Nottage So Godot does not have a 4x4 matrix class,

Unacceptable for a 3D engine. Always good to have one's own stuff ready ...

Archi answered 8/11, 2022 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.