←back to thread

513 points todsacerdoti | 1 comments | | HN request time: 0.213s | source
Show context
FrostKiwi ◴[] No.42192825[source]
Thanks for sharing! Author here, happy to answer any questions.
replies(14): >>42193691 #>>42193836 #>>42193884 #>>42194114 #>>42195074 #>>42195398 #>>42196248 #>>42196427 #>>42196783 #>>42197142 #>>42197506 #>>42198224 #>>42198810 #>>42202062 #
amitp ◴[] No.42195074[source]
Fantastic article! I've been trying to figure out antialiasing for MSDF fonts, and have run across some claims:

1. antialiasing should be done in linear rgb space instead of srgb space [1] [2]

2. because of the lack of (1) for decades, fonts have been tweaked to compensate, so sometimes srgb is better [3] [4]

Do you have advice on linear vs srgb space antialiasing?

[1] https://www.puredevsoftware.com/blog/2019/01/22/sub-pixel-ga...

[2] http://hikogui.org/2022/10/24/the-trouble-with-anti-aliasing...

[3] https://news.ycombinator.com/item?id=12023985

[4] http://hikogui.org/2022/10/24/the-trouble-with-anti-aliasing...

replies(1): >>42200595 #
1. FrostKiwi ◴[] No.42200595[source]
> Do you have advice on linear vs srgb space antialiasing?

Unfortunately, this is completely context dependent. One central point is, whether or not the graphics pipeline is instructed to perform corrections (GL_FRAMEBUFFER_SRGB in OpenGL), as that changes the answer. Another point is, in which context blending is performed. Luckily the developer has full freedom here and can even specify separate blending for alpha and color [1], something that GPU accelerated terminal emulator Alacritty makes use of [2], though it doesn't do MSDF rendering.

One thing I can say though: The alpha, the fading of edge, has to be linear at the end or perceived as such. Or rather if the edge were to be stretched to 10 pixels, each pixel has to be a 0.1 alpha step. (If smoothstep is used, the alpha has to follow that curve at the end) Otherwise the Anti-Aliasing will be strongly diminished. This is something you can always verify at the end. Correct blending of colors is of course a headache and context specific.

> fonts have been tweaked to compensate, so sometimes srgb is better

This should not concern MSDF rendering. These tweaks happened at specific resolutions with monitors popular at that time. Especially when considering HiDPI modes of modern window systems, all bets are off, DPI scaling completely overthrows any of that. MSDF is size independent and the "tweaks" are mainly thickness adjustments, which MSDF has control over. So if the font doesn't match as it looks in another rendering type, MSDF can correct for it.

[1] https://developer.mozilla.org/en-US/docs/Web/API/WebGLRender...

[2] https://github.com/search?q=repo%3Aalacritty%2Falacritty+ble...