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

jospicjospic 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?
Thanks in advance.
-j

Comments

  • MegalomaniakMegalomaniak Posts: 2,649Admin

    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.

    https://docs.godotengine.org/en/stable/tutorials/shading/shading_reference/shading_language.html#built-in-functions

  • jospicjospic 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?

  • SIsilicon28SIsilicon28 Posts: 715Moderator
    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

  • MegalomaniakMegalomaniak Posts: 2,649Admin
    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. :tongue:

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

  • SIsilicon28SIsilicon28 Posts: 715Moderator
    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.

  • jospicjospic Posts: 12Member

    Thanks, I had already tried some of your suggestions, but without luck.
    I don't understand why this example works perfectly (see line 209):

    http://glslsandbox.com/e#51994.0

  • SIsilicon28SIsilicon28 Posts: 715Moderator

    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) );
    

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file