hn.today

SDF vs. MSDF vs. Slug: GPU Text Rendering

alphapixeldev.com158 points59 comments
Screenshot of SDF vs. MSDF vs. Slug: GPU Text Rendering

Glyphs are vector outlines (Bezier curves and straight segments) whose interior is defined by winding rules, and rendering them on the GPU requires filling shapes correctly, producing clean antialiased edges, and staying sharp across arbitrary scales and 3D transforms without re-rasterizing every frame. Common approaches trade off quality, memory, and runtime cost. Texture atlases bake rasterized glyph bitmaps into a shared texture for extremely fast, portable rendering but blur or pixelate when scaled and explode memory for large CJK sets or multiple sizes. Signed distance fields (SDF) store distance-to-edge per texel, enabling cheap sharp edges and antialiasing from small textures but they round off sharp corners. Multi-channel SDF (MSDF) encodes distances in three channels and uses a median to reconstruct corners accurately; msdfgen is widely used, but MSDF remains an atlas-based, bandwidth- and generation-costly solution that still struggles at extreme minification.

Alternative families tessellate outlines into GPU geometry (Loop-Blinn, NV_path_rendering, Pathfinder, Rive), delivering true resolution independence and excellent results for animated vector art at the cost of tessellation overhead, geometry blowup, antialiasing complexity, and sometimes hardware-specific features. Slug (Eric Lengyel, 2017) avoids atlases and per-frame tessellation by evaluating outlines directly in the fragment shader; its 2019 patent was released to the public domain in March 2026, enabling projects like Slughorn (C++20) to implement it. In short: choose atlases/SDF/MSDF for constrained platforms or baked pipelines; use tessellation, Rive, or now Slug for high-quality, dynamic, resolution-independent text.

Read on alphapixeldev.com59 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Other

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.