Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix half-pixel offsets in scaling renderer #231

Merged
merged 2 commits into from
Dec 2, 2021
Merged

Conversation

parasyte
Copy link
Owner

@parasyte parasyte commented Dec 2, 2021

  • This bug was very subtle. It can be hard to notice!
  • Context: When the scaling renderer transformation matrix is created, it needs to center the image within the border.
  • The previous code always evaluated the translation to (0, 0)
  • This PR makes half-pixel adjustments to the translation when needed, making it impossible to rasterize the texture on a half-pixel boundary.
  • I spotted this while working on pixel-aspect-ratio support, but it can most easily be witnessed in the conway example by grabbing the top or bottom resize handle on the window and slow dragging it up and down by 1-pixel-at-a-time. When you hit a half-pixel bug the entire texture will change slightly; some pixels will become hidden or incorrectly duplicated.

This bug is amazing! I can't believe I never noticed it, considering how seriously I take pixel-perfect rendering.

Here are some zoomed-in screenshots of before-and-after to highlight the bug. The object is intended to look more-or-less circular. This first image demonstrates a half-pixel offset on the vertical axis:

Before:

before

After:

after


And just in case you have trouble seeing it, here is an image that composes both together with the after version blended using the difference operation at 95% opacity. This should make it very clear how the half-pixel offset hides and duplicates pixels.

difference

- This bug was very subtle. It can be hard to notice!
- Context: When the scaling renderer transformation matrix is created,
  it needs to center the image within the border.
- The previous code always evaluated the translation to (0, 0)
- This PR makes half-pixel adjustments to the translation when needed,
  making it impossible to rasterize the texture on a half-pixel
  boundary.
- I spotted this while working on pixel-aspect-ratio support, but it can
  most easily be witnessed in the `conway` example by grabbing the top
  or bottom resize handle on the window and slow dragging it up and down
  by 1-pixel-at-a-time. When you hit a half-pixel bug the entire texture
  will change slightly; some pixels will become hidden.
@parasyte parasyte merged commit 2a4ebbf into main Dec 2, 2021
@parasyte parasyte deleted the fix/half-pixel-offsets branch December 2, 2021 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant