‹ BackHN Continuity

Thread

SDF vs. MSDF vs. Slug: GPU Text Rendering

180 points · 72 comments · ibobev

  1. mattdesl · · focus · HN ↗
    I've also been working on a GPU curve renderer, Windfoil, based on a formulation that Fable 5 originally proposed to me during a directed search [1]. It is similar in some ways to Slug, not always as fast, but uses less shader storage (single band instead of two) and produces higher quality anti-aliasing i.e. closer to a box-filtered ground truth.

    It may be of interest to some game/graphics devs here...

    [1] <a href="https:&#x2F;&#x2F;github.com&#x2F;texel-org&#x2F;windfoil-algorithm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;texel-org&#x2F;windfoil-algorithm

    1. yeoyeo42 · · focus · HN ↗
      interesting. how does the AA work in your algorithm?

      the reason slug has two bands is precisely because of its anti-aliasing. you having only one implies you do the AA differently, or are less efficient with searches off the main direction.

      for readers: the slug shader traces two rays, one horizontally, and one vertically, to find out if a pixel is inside a glyph or outside. one would be enough for pure inside outside, but for anti-aliasing purposes it&#x27;s also helpful to know how far away you are from the closest edge. but if you have a horizontal ray running parallel to a horizontal glyph edge (not uncommon), the ray glyph intersection will return no value at all. so slug traces two rays and blends between them for anti-aliasing that always works in both cases. the bands mentioned here are just acceleration structures, basically a list of cells where each tells you which parts of a glyph are contained within it.

      it&#x27;s still approximate. a true ground truth would just supersample and do many point-in-glyph tests within one real pixel - at edges some of them would be inside, and some of them would be outside, giving you a smooth value to display depending on the shape of the glyph within the edge pixel.

      1. mattdesl · · focus · HN ↗
        Windfoil uses boundary integrals to average winding over a given rectangular footprint (normally one pixel, independently in a fragment shader). For many cases, like typical text glyphs, this will reproduce a box-filtered ground truth exactly, i.e. for those shapes it is not approximating AA like Slug or MSDF. But because it takes the average and then applies a fill rule after, it&#x27;s not an exact in all cases (fwiw, Slug can produces similar errors with tricky self-crossing curves and such).
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.