‹ BackHN Continuity

Thread

SDF vs. MSDF vs. Slug: GPU Text Rendering

180 points · 72 comments · ibobev

  1. jayd16 · · focus · HN ↗
    Is there a runtime comparison of the shaders needed? Seems like you might have to do a lot of texture sampling if you have to walk the ray through the data but maybe there's a trick?

    MSDF is pretty much just the target texel in question plus the surrounding samples in a way the GPU can do entirely upfront before the math starts. (M)SDF glyphs also play nicely with mip mapping and I would think this Slug algorithm needs uncompressed data. Maybe that doesn't matter because you just don't scale the data ever?

    1. flohofwoe · · focus · HN ↗
      Slug doesn't use "bitmap" font data but more like parameter lookup tables in storage buffers, pre-processed from TTF files. The lookup data can of course also live in textures (so that it works in WebGL), but using those textures as "poor-man's storage buffers", e.g. fetching the data directly without filtering.

      The pixel shader is indeed quite complex compared to SDF:

      <a href="https:&#x2F;&#x2F;github.com&#x2F;floooh&#x2F;sokol-samples&#x2F;blob&#x2F;8afa83928ce1870efeb0d513e7c4dce4f5db7b3e&#x2F;sapp&#x2F;slug-sapp.glsl#L30-L169" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;floooh&#x2F;sokol-samples&#x2F;blob&#x2F;8afa83928ce1870...

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.