mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shaderir/msl: bug fix: mod for a vector and a scalar didn't work
Updates #2029
This commit is contained in:
parent
52376170a4
commit
dcccd27629
@ -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);
|
||||
}`
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user