Draft: Premultiply font textures for linear blending #1765
Closed
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.
It is my understanding that egui blends colours in linear space (which is arguably more correct than the SRGB blending of yore). However font textures in egui currently use alpha premultiplied pixels values in srgb space. This leads to darkened text edges when using linear blending, this is particularly noticeable with white text on a white background (see below).
This PR changes the font pixel premultiplication function to get (afaict) correctly premultiplied values for linear blending.
This problem and solution is well described in this article: https://hacksoflife.blogspot.com/2022/06/srgb-pre-multiplied-alpha-and.html
Notes: The Ubuntu thin font on white backgrounds can appear thinner due to this change (because it removes the grey border around text). I think the result is still legible and looks better but some other users may disagree. A future release may wish to use a slightly thicker default font if this comes up in feedback.
Related:
#1410
#1412
#1411