From 1785b6a670b211e2d976eb78e1a2588ad35389d6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 15 Jun 2020 00:17:13 +0900 Subject: [PATCH] examples/moire: Add a smaller scale, and remove AdjustTexel function from shaders This can reproduce the bug reported at #669. Apparently, the fix (8827520d4a480b5e5259d2220ddec676caa5bd09) is no longer required after 3550abef7a25ecf548b3711d4ea64be1f08aa226. That's pretty odd, but examples/moire proves this fact. Updates #669 Updates #759 --- examples/moire/main.go | 4 +++- internal/graphicsdriver/metal/graphics.go | 15 --------------- internal/graphicsdriver/opengl/defaultshader.go | 17 ----------------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/examples/moire/main.go b/examples/moire/main.go index e2f9bd94b..dcf01c9bd 100644 --- a/examples/moire/main.go +++ b/examples/moire/main.go @@ -71,12 +71,14 @@ func (g *game) Update(screen *ebiten.Image) error { if inpututil.IsKeyJustPressed(ebiten.KeyS) { switch g.scale { + case 0.5: + g.scale = 1 case 1: g.scale = 1.5 case 1.5: g.scale = 2 case 2: - g.scale = 1 + g.scale = 0.5 default: panic("not reached") } diff --git a/internal/graphicsdriver/metal/graphics.go b/internal/graphicsdriver/metal/graphics.go index d3327aedf..eb591bd0c 100644 --- a/internal/graphicsdriver/metal/graphics.go +++ b/internal/graphicsdriver/metal/graphics.go @@ -93,19 +93,6 @@ vertex VertexOut VertexShader( return out; } -// AdjustTexels adjust texels. -// See #669, #759 -float2 AdjustTexel(float2 source_size, float2 p0, float2 p1) { - const float2 texel_size = 1.0 / source_size; - if (fract((p1.x-p0.x)*source_size.x) == 0.0) { - p1.x -= texel_size.x / 512.0; - } - if (fract((p1.y-p0.y)*source_size.y) == 0.0) { - p1.y -= texel_size.y / 512.0; - } - return p1; -} - float FloorMod(float x, float y) { if (x < 0.0) { return y - (-x - y * floor(-x/y)); @@ -154,7 +141,6 @@ struct ColorFromTexel { float2 p0 = v.tex - texel_size / 2.0; float2 p1 = v.tex + texel_size / 2.0; - p1 = AdjustTexel(source_size, p0, p1); p0 = AdjustTexelByAddress
(p0, v.tex_region); p1 = AdjustTexelByAddress
(p1, v.tex_region); @@ -193,7 +179,6 @@ struct ColorFromTexel { float2 p0 = v.tex - texel_size / 2.0 / scale; float2 p1 = v.tex + texel_size / 2.0 / scale; - p1 = AdjustTexel(source_size, p0, p1); float4 c0 = texture.sample(texture_sampler, p0); float4 c1 = texture.sample(texture_sampler, float2(p1.x, p0.y)); diff --git a/internal/graphicsdriver/opengl/defaultshader.go b/internal/graphicsdriver/opengl/defaultshader.go index ba29885b4..80e15f264 100644 --- a/internal/graphicsdriver/opengl/defaultshader.go +++ b/internal/graphicsdriver/opengl/defaultshader.go @@ -156,20 +156,6 @@ varying highp vec2 varying_tex; varying highp vec4 varying_tex_region; varying highp vec4 varying_color_scale; -// adjustTexel adjusts the two texels and returns the adjusted second texel. -// When p1 - p0 is exactly equal to the texel size, jaggy can happen on macOS (#669). -// In order to avoid this jaggy, subtract a little bit from the second texel. -highp vec2 adjustTexel(highp vec2 p0, highp vec2 p1) { - highp vec2 texel_size = 1.0 / source_size; - if (fract((p1.x-p0.x)*source_size.x) == 0.0) { - p1.x -= texel_size.x / 512.0; - } - if (fract((p1.y-p0.y)*source_size.y) == 0.0) { - p1.y -= texel_size.y / 512.0; - } - return p1; -} - highp float floorMod(highp float x, highp float y) { if (x < 0.0) { return y - (-x - y * floor(-x/y)); @@ -211,7 +197,6 @@ void main(void) { highp vec2 p0 = pos - texel_size / 2.0; highp vec2 p1 = pos + texel_size / 2.0; - p1 = adjustTexel(p0, p1); p0 = adjustTexelByAddress(p0, varying_tex_region); p1 = adjustTexelByAddress(p1, varying_tex_region); @@ -246,8 +231,6 @@ void main(void) { highp vec2 p0 = pos - half_scaled_texel_size; highp vec2 p1 = pos + half_scaled_texel_size; - p1 = adjustTexel(p0, p1); - vec4 c0 = texture2D(texture, p0); vec4 c1 = texture2D(texture, vec2(p1.x, p0.y)); vec4 c2 = texture2D(texture, vec2(p0.x, p1.y));