From d1d40cd839e2f07705faf8b55a729262d7f4c97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 10 Sep 2017 09:47:38 +0200 Subject: [PATCH] Fix rare aliasing artifacts --- src/ImageCanvas.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ImageCanvas.cpp b/src/ImageCanvas.cpp index abb6bc81..1ba5e66f 100644 --- a/src/ImageCanvas.cpp +++ b/src/ImageCanvas.cpp @@ -375,9 +375,10 @@ Transform ImageCanvas::transform(const Image* image) { return Scaling(2.0f / mSize.x(), -2.0f / mSize.y()) * mTransform * - // Translate by 1/10000th of a pixel to avoid pixel edges lying exactly on fragment edges. - // This avoids artifacts caused by inconsistent rounding. - Translation2f(Vector2f::Constant(0.0001f)) * + // Translate by a quarter of a pixel to avoid pixel boundaries aligning perfectly with texels. + // I do not use a value of 0.5, because texel-pixel alignment _can_ already be off by exactly + // 0.5 if the image has an odd resolution. + Translation2f(Vector2f::Constant(0.25f)) * Scaling(image->size().cast() / mPixelRatio) * Translation2f(Vector2f::Constant(-0.5f)); } @@ -392,7 +393,7 @@ Transform ImageCanvas::textureToNanogui(const Image* image) { Translation2f(0.5f * mSize.cast()) * mTransform * Scaling(1.0f / mPixelRatio) * - Translation2f(-0.5f * image->size().cast()); + Translation2f(-0.5f * image->size().cast() + Vector2f::Constant(0.25f)); } TEV_NAMESPACE_END