Text rendering using multi channel signed distance fields
github.com
github.com
Really enjoyed this paper, the talk, and this technique. Quite clever!
I was building a 3D game for language learning on mobile, and the font rendering in Unity3D was awful (blurry and rasterized).
When I eventually ended up writing my own engine, I started with bitmap fonts and quickly switched to SDF shaders. I ended up having to regenerate the texture on-the-fly as new characters were needed, acting as a cache (one of the markets was China -- you're not going to just stash all of the characters into one texture).
Another wrinkle: There's also right-to-left writing systems like Hebrew and Arabic, but those weren't our markets.
So far, the best I've seen is Eric Lengyel's Slug library: [1] http://sluglibrary.com/
It is vastly better than standard Unity text rendering in every way.
This is a note for future readers, and less of a reply.
Not sure about Unity, but it helps to be able to submit the geometry, the shader, and the uniforms, then asynchronously (or if you're lucky, in another thread) submit the SDF after you're done computing it.
This is going to happen with every SDF format. The problem is that SDFs can fundamentally only encode the distance to a small fixed number of lines per texel. For regular SDF, that number is one; for mSDF, that number is two. If the complexity of the shape exceeds that (as can happen for complex fonts such as CJK fonts with small SDFs), then artefacts will occur.
If you're going to use this library, note that the maintenance situation is complicated. Some forks seem well ahead in terms of bug fixes, for example https://github.com/RCrockford/msdfgen
The trouble with using this property to encode and render polygons is that sometimes to render polygons properly you need to consider the distance to two or more edges simultaneously in the course of processing a pixel. A single-channel signed distance field just accepts the artefacts that result from this. A three-channel signed distance field, on the other hand, allows each texel to record the distance to two edges simultaneously. (The extra channel basically exists just to specify the Boolean operation to be performed on the two edge differences.) This enhances the quality, especially around sharp edges.
Note that rendering of general polygons with any sort of signed distance field remains an approximation, because of the limited number of edges per texel as explained above. SDFs are not general vector renderers and should not be treated as such.
† Modulo quantization error from the fact that you're encoding distance into an 8-bit channel.
The Valve technique starts with "distance to the edge" encoded in each pixel of the texture. Bilinear filtering turns that into a piecewise-linear approximation of the true value for each interpolated point. Thresholding that gives you a black or white depending on if a given point is inside or outside of the threshold distance from the edge. Thus, you get hard, straight edged results at pixel resolution regardless of resolution of the font texture.
This technique extends Valve's by combining multiple piecewise-linear approximations to work around the limitations of approximating corners that are not aligned with the texel grid.