mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples/moire: Add a smaller scale, and remove AdjustTexel function from shaders
This can reproduce the bug reported at #669. Apparently, the fix (8827520d4a
) is no longer required after3550abef7a
. That's pretty odd, but examples/moire proves this fact. Updates #669 Updates #759
This commit is contained in:
parent
6d25f7eaeb
commit
1785b6a670
@ -71,12 +71,14 @@ func (g *game) Update(screen *ebiten.Image) error {
|
|||||||
|
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
|
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
|
||||||
switch g.scale {
|
switch g.scale {
|
||||||
|
case 0.5:
|
||||||
|
g.scale = 1
|
||||||
case 1:
|
case 1:
|
||||||
g.scale = 1.5
|
g.scale = 1.5
|
||||||
case 1.5:
|
case 1.5:
|
||||||
g.scale = 2
|
g.scale = 2
|
||||||
case 2:
|
case 2:
|
||||||
g.scale = 1
|
g.scale = 0.5
|
||||||
default:
|
default:
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
|
@ -93,19 +93,6 @@ vertex VertexOut VertexShader(
|
|||||||
return out;
|
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) {
|
float FloorMod(float x, float y) {
|
||||||
if (x < 0.0) {
|
if (x < 0.0) {
|
||||||
return y - (-x - y * floor(-x/y));
|
return y - (-x - y * floor(-x/y));
|
||||||
@ -154,7 +141,6 @@ struct ColorFromTexel<FILTER_LINEAR, address> {
|
|||||||
|
|
||||||
float2 p0 = v.tex - texel_size / 2.0;
|
float2 p0 = v.tex - texel_size / 2.0;
|
||||||
float2 p1 = v.tex + texel_size / 2.0;
|
float2 p1 = v.tex + texel_size / 2.0;
|
||||||
p1 = AdjustTexel(source_size, p0, p1);
|
|
||||||
p0 = AdjustTexelByAddress<address>(p0, v.tex_region);
|
p0 = AdjustTexelByAddress<address>(p0, v.tex_region);
|
||||||
p1 = AdjustTexelByAddress<address>(p1, v.tex_region);
|
p1 = AdjustTexelByAddress<address>(p1, v.tex_region);
|
||||||
|
|
||||||
@ -193,7 +179,6 @@ struct ColorFromTexel<FILTER_SCREEN, address> {
|
|||||||
|
|
||||||
float2 p0 = v.tex - texel_size / 2.0 / scale;
|
float2 p0 = v.tex - texel_size / 2.0 / scale;
|
||||||
float2 p1 = 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 c0 = texture.sample(texture_sampler, p0);
|
||||||
float4 c1 = texture.sample(texture_sampler, float2(p1.x, p0.y));
|
float4 c1 = texture.sample(texture_sampler, float2(p1.x, p0.y));
|
||||||
|
@ -156,20 +156,6 @@ varying highp vec2 varying_tex;
|
|||||||
varying highp vec4 varying_tex_region;
|
varying highp vec4 varying_tex_region;
|
||||||
varying highp vec4 varying_color_scale;
|
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) {
|
highp float floorMod(highp float x, highp float y) {
|
||||||
if (x < 0.0) {
|
if (x < 0.0) {
|
||||||
return y - (-x - y * floor(-x/y));
|
return y - (-x - y * floor(-x/y));
|
||||||
@ -211,7 +197,6 @@ void main(void) {
|
|||||||
highp vec2 p0 = pos - texel_size / 2.0;
|
highp vec2 p0 = pos - texel_size / 2.0;
|
||||||
highp vec2 p1 = pos + texel_size / 2.0;
|
highp vec2 p1 = pos + texel_size / 2.0;
|
||||||
|
|
||||||
p1 = adjustTexel(p0, p1);
|
|
||||||
p0 = adjustTexelByAddress(p0, varying_tex_region);
|
p0 = adjustTexelByAddress(p0, varying_tex_region);
|
||||||
p1 = adjustTexelByAddress(p1, 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 p0 = pos - half_scaled_texel_size;
|
||||||
highp vec2 p1 = pos + half_scaled_texel_size;
|
highp vec2 p1 = pos + half_scaled_texel_size;
|
||||||
|
|
||||||
p1 = adjustTexel(p0, p1);
|
|
||||||
|
|
||||||
vec4 c0 = texture2D(texture, p0);
|
vec4 c0 = texture2D(texture, p0);
|
||||||
vec4 c1 = texture2D(texture, vec2(p1.x, p0.y));
|
vec4 c1 = texture2D(texture, vec2(p1.x, p0.y));
|
||||||
vec4 c2 = texture2D(texture, vec2(p0.x, p1.y));
|
vec4 c2 = texture2D(texture, vec2(p0.x, p1.y));
|
||||||
|
Loading…
Reference in New Issue
Block a user