From 6dfcde1f48083eb6c1b44dd844ff799a72cbc799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Oct 2015 21:16:24 +0100 Subject: [PATCH] TextureTools: improve distance field computation without texelFetch(). GL 3.2 has texelFetch() and layout(pixel_center_integer), which means that we integer coordinates with no precision loss when addressing individual pixels in the source texture. In the versions before we have to craft floating-point coordinates for texture() to grab the value of wanted pixel with no jumping around or interpolation. This change improves the behavior *a bit*, but not fully. I'm postponing this to the point when I have an unit test that compares the output with ground truth. --- src/Magnum/TextureTools/DistanceFieldShader.frag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magnum/TextureTools/DistanceFieldShader.frag b/src/Magnum/TextureTools/DistanceFieldShader.frag index 935dc0e0e..4088e55d5 100644 --- a/src/Magnum/TextureTools/DistanceFieldShader.frag +++ b/src/Magnum/TextureTools/DistanceFieldShader.frag @@ -87,7 +87,7 @@ void main() { #ifdef TEXELFETCH_USABLE const mediump ivec2 position = ivec2(gl_FragCoord.xy*scaling); #else - const mediump vec2 position = gl_FragCoord.xy*scaling*imageSizeInverted; + const mediump vec2 position = (gl_FragCoord.xy - vec2(0.5))*scaling*imageSizeInverted; #endif /* If pixel at the position is inside (1), we are looking for nearest pixel @@ -111,7 +111,7 @@ void main() { #ifdef TEXELFETCH_USABLE const lowp ivec2 offset = ivec2(-i+j, i); #else - const lowp vec2 pixelOffset = vec2(float(-i+j), float(i)); + const lowp vec2 pixelOffset = vec2(float(-i+j), float(i)) + vec2(0.5); const lowp vec2 offset = pixelOffset*imageSizeInverted; #endif