slug-font-rendering
slug-font-rendering — an installable skill for AI agents.
By reason-machines · 1,275 installs
npx skills add reason-machines/trending-skills --skill slug-font-rendering
Source repository · Upstream listing
Slug Font Rendering Algorithm
Skill by [ara.so](https://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](https://jcgt.org/published/0006/02/02/)
Blog (updates): [A Decade of Slug](https://terathon.com/blog/decade slug.html)
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
Problem Cause Fix
Glyph appears hollow/inverted Winding order reversed Check contour orientation; TrueType uses clockwise for outer contours
Jagged edges Anti aliasing not applied Ensure distance to edge is computed and used in final coverage
Performance poor Band optimization not active Verify per fragment curve count is small (< ~20); increase band count
Cubic curves not rendering OTF cubic Béziers unsupported natively Split cubics into quadratic approximations on CPU
Artifacts at glyph overlap Curves not clipped to band Clip curve Y range to band extents before upload
Black box instead of glyph Blend state wrong Use premultiplied alpha blend (ONE, INV SRC ALPHA)
Missing glyphs Band offset incorrect Validate bandOffset indexing aligns with buffer layout
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/)
References
[Slug Algorithm Paper (JCGT 2017)](https://jcgt.org/published/0006/02/02/)
[A Decade of Slug — Blog Post](https://terathon.com/blog/decade slug.html)
[GitHub Repository](https://github.com/EricLengyel/Slug)