SDF and multi-channel SDF text rendering
Bakes glyph or icon outlines into low-resolution distance textures; a shader thresholds the sampled distance, giving crisp edges at any scale, and the multi-channel form keeps sharp corners.
Also known as MSDF, msdfgen, distance field fonts, Valve alpha-tested magnification
In the family Geometry, meshing & signed distance fields, distance-field vector textures
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Plugin | npm i troika-three-text docs |
| Babylon.js 9.38.0 | Official add-on | import { TextRenderer } from "@babylonjs/addons" (msdfText) docs |
| Godot 4.7 | Built in | FontFile.multichannel_signed_distance_field = true (Label3D/Label/RichTextLabel) docs Also SDF-style rendering of 3D text via Label3D. |
| Unity | Official add-on | TextMeshPro SDF font assets (Font Asset Creator) docs Single-channel SDF; MSDF is not built in. |
| Unreal 5.7 | Built in | SlateCore FontSdfSettings (FFontSdfSettings) for signed distance field glyph rendering docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
For each glyph, compute a signed distance to the outline at every texel of a small atlas cell, clamped to a pixel range and remapped to 0..1 with 0.5 on the edge. At draw time the shader samples bilinearly, which interpolates distances far better than it interpolates coverage, then applies a smoothstep around 0.5 with a width taken from screen-space derivatives for antialiasing. Outlines, glows and drop shadows are just different thresholds. A single channel rounds off sharp corners because distance is a poor description there. Multi-channel SDFs colour the outline edges so that each RGB channel stores the distance to a subset of edges, with adjacent edges sharing a channel, and the shader takes the median of the three. The median reproduces the sharp corner while far from corners all three agree. A fourth channel often holds a true SDF for effects.
When to choose it
Reach for it when
- text looks blurry when zoomed in on a texture
- glyph corners get rounded in sdf font atlas
- need crisp ui text at any scale in a shader
- outline and glow on text without extra passes
Choose it for UI, labels and world-space text that must stay sharp under zoom and perspective without big atlases. Prefer plain bitmap fonts when scale is fixed, and Exact Euclidean Distance Transform or Jump Flooding Algorithm when you only need to generate a single-channel field from a raster. Prefer direct GPU curve rendering (Slug-style) for huge glyphs or extreme magnification.
Field marks
- Single-channel SDF rounds corners and drops thin serifs at low atlas resolution
- MSDF can show stray colour fringes or blobs where overlapping contours confuse the channel assignment unless the font is preprocessed
- Very small text loses hinting, so stems blur compared with a hinted rasteriser
- Atlas range too small clips outlines and glows; too large wastes precision and softens edges
Presets
Median-of-three decode of a procedural glyph
{
"zoom_min": 0.55,
"zoom_max": 1.6,
"px_range": 6
}Show GLSL (46 lines)
// GLSL ES 3.0, Shadertoy-style. Procedural 5-edge glyph encoded as a 3-channel signed distance,
// then decoded with the median trick. Sharp corners survive at any zoom.
const float ZOOM_MIN = 0.55;
const float ZOOM_MAX = 1.6;
const float PX_RANGE = 6.0;
float median(float a, float b, float c) { return max(min(a, b), min(max(a, b), c)); }
vec3 glyphMSDF(vec2 p) {
vec2 P[5];
P[0] = vec2(-0.5, -0.45); P[1] = vec2(0.5, -0.45); P[2] = vec2(0.5, 0.15);
P[3] = vec2(0.0, 0.6); P[4] = vec2(-0.5, 0.15);
vec3 ch = vec3(-1e3);
for (int i = 0; i < 5; i++) {
vec2 a = P[i], b = P[(i + 1) % 5];
vec2 e = normalize(b - a);
vec2 n = vec2(e.y, -e.x); // outward normal for counter-clockwise winding
float s = dot(p - a, n); // signed distance to the infinite edge line
int col = (i == 4) ? 1 : (i % 3); // edge colours 0,1,2,0,1
for (int k = 0; k < 2; k++) {
int c = (col + k) % 3;
ch[c] = max(ch[c], s);
}
}
return ch;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float zoom = mix(ZOOM_MIN, ZOOM_MAX, 0.5 + 0.5 * sin(iTime));
float ang = 0.35 * sin(iTime * 0.7);
mat2 R = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));
vec2 g = R * uv / zoom;
vec3 m = glyphMSDF(g);
float sd = -median(m.r, m.g, m.b); // positive inside
float screenPx = PX_RANGE * 0.5 / (iResolution.y * 0.5) * zoom; // unit-space size of one pixel-ish
float aa = fwidth(sd) * 0.75 + 1e-4;
float fill = smoothstep(-aa, aa, sd);
float outline = smoothstep(-aa, aa, sd + 0.05) - fill;
vec3 bg = mix(vec3(0.10, 0.11, 0.16), vec3(0.22, 0.2, 0.3), uv.y + 0.5);
vec3 col = bg;
col = mix(col, vec3(0.05, 0.05, 0.08), outline);
col = mix(col, mix(vec3(1.0, 0.85, 0.4), vec3(1.0, 0.45, 0.3), g.y + 0.5), fill);
fragColor = vec4(col, 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| msdf-median-glyph | Tesla T4 1920x1080 | 1.57× baseline (feather) · 0.052 ms / 0.054 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| msdf-median-glyph | NVIDIA L4 1920x1080 | 1.15× baseline (feather) · 0.018 ms / 0.018 ms · 2.8× faster on L4 | opengl-timer-query · Cross-architecture validation |
| msdf-median-glyph | NVIDIA A100-SXM4-40GB 1920x1080 | 1.01× baseline (feather) · 0.029 ms / 0.029 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Exact Euclidean Distance Transform: Produces the single-channel distance field from a rasterised glyph that the alpha channel or simple SDF text uses.
Sources
- primaryChris Green (2007). Improved alpha-tested magnification for vector textures and special effects. ACM SIGGRAPH 2007 courses.Verified via crossref · 2026-11-29doi:10.1145/1281500.1281665
- implementationChlumsky (2016). Chlumsky/msdfgen. Multi-channel signed distance field generatorGitHub API · license MIT · 2026-11-29
- implementationChlumsky (2020). Chlumsky/msdf-atlas-gen. MSDF font atlas generatorGitHub API · license MIT · 2026-11-29
- implementationprotectwise (2019). protectwise/troika. A JavaScript framework for interactive 3D and 2D visualizationsGitHub API · license MIT · 2026-11-29