<p>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.</p>
<p>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.</p>
<p>A subtlety here is that if you want to render colored text, or text over different backgrounds, then you will need to use <a href="https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#framebuffer-dsb" rel="nofollow noreferrer">dual-source blending</a> in order to correctly blend all three subpixels independently, using the three glyph evaluations as alpha values.</p>
<p>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.</p>

CC BY-SA 4.0
2021-11-29T21:57:44.927Z
does that mean I would render the scene 3 times, once for each subpixel?
griips21
CC BY-SA 4.0
2021-11-30T05:23:58.643Z
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.
Nathan Reed
CC BY-SA 4.0
2021-11-27T06:38:15.547Z
2021-11-27T06:38:15.547Z
Nathan Reed
<p>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.</p>
<p>Does anybody know a high level overview on how to implement subpixel antialiasing in vulkan?</p>

<vulkan><antialiasing>
How can I implement subpixel antialiasing for font rasterization in Vulkan?
griips21
# How can I implement subpixel antialiasing for font rasterization in Vulkan?

(Asked by: username_0 on 2021-11-22)

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?

**Tags:** vulkan, antialiasing


---

## 1 answers

### Answer by username_1 on 2021-11-27. Score: 1 | Accepted answer

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](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#framebuffer-dsb) 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.

> **Comments:**
> **username_0**: does that mean I would render the scene 3 times, once for each subpixel?  
> **username_1**: 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.  

---

