2
$\begingroup$

As a hobby project I am creating text rendering application that renders text directly from glyph outlines. Currently I am trying to find info on how to implement subpixel antialiasing. I know that vulkan supports MSAA but that samples the pixels from predefined locations and for subpixel antialiasing I assume I would have to specify sampling locations myself.

Does anybody know a high level overview on how to implement subpixel antialiasing in vulkan?

$\endgroup$

1 Answer 1

1
$\begingroup$

At the high level it's not too difficult. Most laptop/desktop displays have three vertical subpixels, in RGB order from left to right. Given that, in your fragment shader you will need to evaluate the glyph outlines three times, using sample points at the center of each subpixel. Since the usual sample point for a fragment shader is at the pixel center, you would want to offset it by 1/3 of a pixel left and right to get the other two sample points.

If you do any antialiasing as part of your glyph outline evaluation (e.g. estimating how much of the pixel area is covered), you would likewise want to narrow the antialiasing kernel to cover only 1/3 of the width of the pixel, instead of the whole pixel.

A subtlety here is that if you want to render colored text, or text over different backgrounds, then you will need to use dual-source blending in order to correctly blend all three subpixels independently, using the three glyph evaluations as alpha values.

However, note that displays might have the subpixels in other orientations (which can change dynamically as the user rotates the display in the case of phones and tablets), and some displays have pentile layouts which are more complex. For subpixel rendering to work, your sample points need to adapt to the layout of the actual display you're running on, but I'm not sure if there is any reasonable way to query this information. It's for this reason, plus the general increase in display DPIs making subpixel rendering less advantageous, that people have generally moved away from subpixel text rendering in recent years.

$\endgroup$
2
  • $\begingroup$ does that mean I would render the scene 3 times, once for each subpixel? $\endgroup$
    – griips21
    Commented Nov 29, 2021 at 21:57
  • 1
    $\begingroup$ No, render the scene once but in your fragment shader that evaluates the glyph outlines or whatever, call your glyph sampling code three times. Or if you were rendering glyphs from a texture atlas you'd sample that three times. $\endgroup$ Commented Nov 30, 2021 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.