Skip to content

Commit

Permalink
Fix rare aliasing artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom94 committed Sep 10, 2017
1 parent 76f243d commit d1d40cd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ImageCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,10 @@ Transform<float, 2, 2> 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<float>() / mPixelRatio) *
Translation2f(Vector2f::Constant(-0.5f));
}
Expand All @@ -392,7 +393,7 @@ Transform<float, 2, 2> ImageCanvas::textureToNanogui(const Image* image) {
Translation2f(0.5f * mSize.cast<float>()) *
mTransform *
Scaling(1.0f / mPixelRatio) *
Translation2f(-0.5f * image->size().cast<float>());
Translation2f(-0.5f * image->size().cast<float>() + Vector2f::Constant(0.25f));
}

TEV_NAMESPACE_END

0 comments on commit d1d40cd

Please sign in to comment.