From e5a2cf29c0efd8d5fc836bdf12e64b7613bdc4ed Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 24 Feb 2018 01:16:32 +0900 Subject: [PATCH] graphics: Bug fix: pixel coord is upper-left by default --- internal/graphics/shader.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/graphics/shader.go b/internal/graphics/shader.go index 40e716fcf..39cb5fd17 100644 --- a/internal/graphics/shader.go +++ b/internal/graphics/shader.go @@ -104,6 +104,7 @@ void main(void) { // adjustment, texels can be exactly as same values as the (lower and left) edges' // positions and it could happen that outside of the source is rendered. (#491) // 1.0 / 4096.0 is an arbitrary number that doesn't cause problems on MacBook Pro. + // TODO: Adding is better? pos.x = min(varying_tex_coord_max.x - 1.0 / 4096.0, pos.x); pos.y = min(varying_tex_coord_max.y - 1.0 / 4096.0, pos.y); @@ -120,7 +121,6 @@ void main(void) { #if defined(FILTER_LINEAR) pos = roundTexel(pos); highp vec2 texel_size = 1.0 / source_size; - pos -= texel_size * 0.5; highp vec2 p0 = pos; highp vec2 p1 = pos + texel_size; @@ -152,7 +152,6 @@ void main(void) { #if defined(FILTER_SCREEN) pos = roundTexel(pos); highp vec2 texel_size = 1.0 / source_size; - pos -= texel_size * 0.5 / scale; highp vec2 p0 = pos; highp vec2 p1 = pos + texel_size / scale; @@ -162,7 +161,7 @@ void main(void) { vec4 c3 = texture2D(texture, p1); // Texels must be in the source rect, so it is not necessary to check that like linear filter. - vec2 rate = clamp((fract(pos * source_size) - 0.5) * scale + 0.5, 0.0, 1.0); + vec2 rate = clamp((fract(pos * source_size) - vec2(0.5, 0.5)) * scale + vec2(0.5, 0.5), vec2(0.0, 0.), vec2(1.0, 1.0)); vec4 color = mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y); #endif