Slug Font Rendering Algorithm
Skill by ara.so — Daily 2026 Skills collection.
Slug is a reference implementation of the Slug font rendering algorithm — a GPU-accelerated technique for rendering vector fonts and glyphs at arbitrary scales with high quality anti-aliasing. It works by encoding glyph outlines as lists of quadratic Bézier curves and line segments, then resolving coverage directly in fragment shaders without pre-rasterized textures.
Paper: JCGT 2017 — Slug Algorithm
Blog (updates): A Decade of Slug
License: MIT — Patent dedicated to public domain. Credit required if distributed.
What Slug Does
- Renders TrueType/OpenType glyphs entirely on the GPU
- No texture atlases or pre-rasterization needed
- Scales to any resolution without quality loss
- Anti-aliased coverage computed per-fragment using Bézier math
- Works with any rendering API that supports programmable shaders (D3D11/12, Vulkan, Metal via translation)
Repository Structure
Installation / Integration
Slug is a reference implementation — you integrate the HLSL shaders into your own rendering pipeline.
Step 1: Clone the Repository
Step 2: Include the Shaders
Copy the .hlsl files into your shader directory and include them in your pipeline:
Step 3: Prepare Glyph Data on the CPU
You must preprocess font outlines (TrueType/OTF) into Slug's curve buffer format:
- Decompose glyph contours into quadratic Bézier segments and line segments
- Upload curve data to a GPU buffer (structured buffer or texture buffer)
- Precompute per-glyph "band" metadata for the band optimization
Core Concepts
Glyph Coordinate System
- Glyph outlines live in font units (typically 0–2048 or 0–1000 per em)
- The fragment shader receives a position in glyph space via interpolated vertex attributes
- Coverage is computed by counting signed curve crossings in the Y direction (winding number)
Curve Data Format
Each curve entry in the GPU buffer stores:
Band Optimization
The glyph bounding box is divided into horizontal bands. Each band stores only the curves that intersect it, reducing per-fragment work from O(all curves) to O(local curves).
Key Shader Code & Patterns
Fragment Shader Entry Point (Conceptual Integration)
Quadratic Bézier Coverage Computation
The heart of the algorithm — computing signed coverage from a quadratic Bézier:
Line Segment Coverage
Anti-Aliasing with Partial Coverage
For smooth edges, use the distance to the nearest curve for sub-pixel anti-aliasing:
Vertex Shader Pattern
CPU-Side Data Preparation (Pseudocode)
Render State Requirements
Common Patterns
Rendering a String
Scaling Text
Scaling is handled entirely on the CPU side by transforming the screen-space quad. The glyph-space coordinates stay constant — the fragment shader always works in font units.
Troubleshooting
Credits & Attribution
Per the license: if you distribute software using this code, you must give credit to Eric Lengyel and the Slug algorithm.
Suggested attribution:
Font rendering uses the Slug Algorithm by Eric Lengyel (https://jcgt.org/published/0006/02/02/)

