Take FXAA samples from half-pixel coordinates to improve quality #66466
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #64985
It looks like the code we use for FXAA is a simplified model based on: https://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-opengl-test-radeon-geforce/3/
One optimization this code makes is to only sample the four corners instead of taking all 8 samples around the current pixel. To make that effective, we need to use linear sampling and offset the samples so they overlap all 8 pixel positions. This can be seen in the linked code, the sample positions are at half-pixel offsets. However, when we implemented the code we used full pixel offsets so we are only getting contributions from the four corner pixels which leads to a lot of missing data which create artifacts.
This change results in a smaller blur, so FXAA is less blurry, but also a reduction in artifacts so there are fewer random jaggies created by the FXAA. This results in both smoother edges and less blurring.
This change can be made in 3.x as well.
Before:
After:
![Screenshot from 2022-09-26 11-41-22](https://user-images.githubusercontent.com/16521339/192356970-84ea58bb-adb1-4e97-8d6c-11d7490265d4.png)
![Screenshot from 2022-09-26 11-40-55](https://user-images.githubusercontent.com/16521339/192356976-b5c579ae-bf00-42d3-a4d8-611156050fb1.png)