Chlumsky /msdfgen

Multi-channel signed distance field generator

★ 4,966⑂ 518👁 103⑃ 64● 159▤ 16◈ 27
C++MITCreated 2016-04-24
4,966
stars
518
forks
103
watchers
64
prs
159
issues
16
releases
27
discussions

README

Multi-channel signed distance field generator

This is a utility for generating signed distance fields from vector shapes and font glyphs,
which serve as a texture representation that can be used in real-time graphics to efficiently reproduce said shapes.
Although it can also be used to generate conventional signed distance fields best known from
this Valve paper
and perpendicular distance fields, its primary purpose is to generate multi-channel distance fields,
using a method I have developed. Unlike monochrome distance fields, they have the ability
to reproduce sharp corners almost perfectly by utilizing all three color channels.

The following comparison demonstrates the improvement in image quality.

!demo-msdf16
!demo-sdf16
!demo-sdf32

- To learn more about this method, you can read my Master's thesis.
- Check out my MSDF-Atlas-Gen if you want to generate entire font atlases for text rendering.
- See what's new in the changelog.

 Getting started

The project can be used either as a library or as a console program. It is divided into two parts, core
and extensions. The core module has no dependencies and only uses bare C++. It contains all
key data structures and algorithms, which can be accessed through the msdfgen.h header.
Extensions contain utilities for loading fonts and SVG files, as well as saving PNG images.
Those are exposed by the msdfgen-ext.h header. This module uses
FreeType,
TinyXML2,
libpng,
and (optionally) Skia.

Additionally, there is the main.cpp, which wraps the functionality into
a comprehensive standalone console program. To start using the program immediately,
there is a Windows binary available for download in the "Releases" section.
To use the project as a library, you may install it via the vcpkg package manager as

vcpkg install msdfgen

Or, to build the project from source, you may use the included CMake script.
In its default configuration, it requires vcpkg as the provider for third-party library dependencies.
If you set the environment variable VCPKG_ROOT to the vcpkg directory,
the CMake configuration will take care of fetching all required packages from vcpkg.

 Console commands

The standalone program is executed as

msdfgen   

where only the input specification is required.

Mode can be one of:
 - sdf – generates a conventional monochrome (true) signed distance field.
 - psdf – generates a monochrome signed perpendicular distance field.
 - msdf (default) – generates a multi-channel signed distance field using my new method.
 - mtsdf – generates a combined multi-channel and true signed distance field in the alpha channel.

The input can be specified as one of:
 - -font \ \ – to load a glyph from a font file.
   Character code can be expressed as either a decimal (63) or hexadecimal (0x3F) Unicode value, or an ASCII character
   in single quotes ('?').
 - -svg \ – to load an SVG file. Note that only the last vector path in the file will be used.
 - -shapedesc \, -definesh

Top issues

Discussions

Latest release

Version 1.13.1 v1.13.1 2026-11-11
- Improved variable font support and added an option to print the available axes
- Added the -pxtranslate setting
- Clang build fix for a specific configuration
- Minor fixes and library API updates

Snapshot: 2026-11-11T21:00:35Z · Data license Apache-2.0 · JSON