internal/shaderir/msl: bug fix: mod for a vector and a scalar didn't work

Updates #2029
This commit is contained in:
Hajime Hoshi 2022-03-26 02:57:34 +09:00
parent 52376170a4
commit dcccd27629
2 changed files with 31 additions and 2 deletions

View File

@ -54,8 +54,8 @@ using namespace metal;
constexpr sampler texture_sampler{filter::nearest};
template<typename T>
T mod(T x, T y) {
template<typename T, typename U>
T mod(T x, U y) {
return x - y * floor(x/y);
}`

View File

@ -625,3 +625,32 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
}
// Issue #2029
func TestShaderModVectorAndFloat(t *testing.T) {
const w, h = 16, 16
dst := ebiten.NewImage(w, h)
s, err := ebiten.NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
r := mod(vec3(0.25, 0.5, 0.75), 0.5)
return vec4(r, 1)
}
`))
if err != nil {
t.Fatal(err)
}
dst.DrawRectShader(w, h, s, nil)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := dst.At(i, j).(color.RGBA)
want := color.RGBA{0x40, 0, 0x40, 0xff}
if !sameColors(got, want, 2) {
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
}