Invalid arguments for built-in function: mat2(vec4)

Posts: 12Member

Hi,
I'm trying to convert a function (glsl) for a Godot shader.
In this code statement I get this compiling error which i can't understand:

`dot(mat2(fract(sin(vec4(0.0, 1.0, 113.0, 114.0) + dot(i, vec2(1.0, 113.0)))*43758.5453))*vec2(1. - p.y, p.y), vec2(1. - p.x, p.x) );`

Any suggestions?
-j

I don't think you can plug a matrix into a dot product. It takes a vector type as input and outputs a scalar value.

• Posts: 12Member

Maybe I'm wrong, but the instruction is formally correct, in fact:

"dot" needs two vectors as arguments, and in the statement there is:

`dot(mat2(...)*vec2, vec2)`
but mat2*vec2 is a vector.

am I right?

• Posts: 757Moderator
edited June 25

Can you give us the error message that pops up, if there is any?
Edit: no wait, that's the title. :P

edited June 25

@jospic said:
Maybe I'm wrong, but the instruction is formally correct, in fact:

"dot" needs two vectors as arguments, and in the statement there is:

`dot(mat2(...)*vec2, vec2)`
but mat2*vec2 is a vector.

am I right?

Hmm, yes I missed it, that should afaik be correct but on closer inspection you also have a `1.` in there that might be causing an issue. And same again in the second vector at the end.

edit: the documentation says:

Construction of matrix types requires vectors of the same dimension as the matrix.

Thus I guess it would need to be a `mat4` to plug a `vec4` into it. You can always swizzle to get the specific components you need out of it. Then again I'd expect the fract and the sine to output scalars so I'm as confused as you, I guess.

I recon it's worth trying to fix those `1.` scalars first.

• Posts: 757Moderator
edited June 25

Looking back at the docs, It looks to me you should construct the mat2 with two vec2's instead of a vec4.

EDIT: I meant a mat2, not mat4. The above post has been corrected.

• Posts: 12Member

I don't understand why this example works perfectly (see line 209):

http://glslsandbox.com/e#51994.0

• Posts: 757Moderator

I don't know what you mean, but using vec2's instead did the trick for me.

``````vec4 temp = fract(sin(vec4(0.0, 1.0, 113.0, 114.0) + dot(i, vec2(1.0, 113.0)))*43758.5453);

// the vec4 is split into two vec2s here in mat2.
dot(mat2(temp.xy, temp.zw)*vec2(1. - p.y, p.y), vec2(1. - p.x, p.x) );
``````