hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
10.92k stars 652 forks source link

Kage: integer arithmetics functions support #2788

Closed Zyko0 closed 7 months ago

Zyko0 commented 1 year ago

Ebitengine Version

v2.7.0-alpha.2

Operating System

Go Version (go version)

1.21

What steps will reproduce the problem?

Kage shader compilation:

package main

func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
    _ = sign(int(8))
    return vec4(0)
}

abs, sign, min/max and clamp functions with integer types (int, ivec2, ivec3, ivec4) (noticed by @tinne26)

What is the expected result?

no error

What happens instead?

compilation error: cannot use int as float, vec2, vec3, or vec4 value in argument to sign

Anything else you feel useful to add?

No response

tinne26 commented 1 year ago

To be fair, this currently works as advertised on https://ebitengine.org/en/documents/shader.html#Built-in_functions_(mathematics). The main offenders would be only min/max, as they don't work like Go1.21 built-in functions if ints are not supported. But then, if you support ints for min/max, it seems weird to not also support them for the few other functions mentioned.

hajimehoshi commented 1 year ago

The difference from Go's min/max is that Kage's min/max takes only two arguments. So, I cannot move min/max to the Go's builtin function section yet.

hajimehoshi commented 1 year ago

See also https://github.com/hajimehoshi/ebiten/issues/2677

hajimehoshi commented 7 months ago

Note to myself:

https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf

Some functions like sin takes only floats and ths is represented as genFType.

hajimehoshi commented 7 months ago

So the build-in functions that can take integers are: