Signed Distance Field Text Rendering
Why Game Development Stack Exchange recommends it
Game Development Stack Exchange answerers point people to it as a visual demonstration of how signed distance fields give crisp text and shapes from small textures.
Recommended by 3 people across 3 different months, 2013 to 2019.
Why Stack Overflow recommends it
Stack Overflow users link it as a concrete example of signed distance fields when answering how to get sharp, resolution-independent text in OpenGL, WebGL, DirectX, Qt and Unity.
Recommended by 2 people across 2 different months, 2014 to 2017.
What it is
A two-minute real-time demo by Paul Houx of signed distance field text rendering, built in Cinder. A font texture with glyphs under 50 pixels is drawn through a simple thresholding shader, and the text stays sharp at large scales. The description links Valve's 2007 SIGGRAPH paper, the font texture tool, and the shader code.
What people said
Recommends msell · 2013-06 · Game Development Stack Exchange · on “How to zoom randomly generated maps?”
This sounds like a good situation to use Signed Distance Fields [LINK] . It's often used for text rendering to achieve high quality and sharp results when zooming (and rotating), but it can also be used for any black & white images. See this video [this video] and the image below. Typically when text is prerasterized to bitmaps, each pixel stores the alpha value. 0 means transparent, 1 means opaque and values between are semitransparent due to antialiasing the edges. With signed distance fields the idea is to create a bitmap where each pixel stores the distance to the nearest edge. Values < 0 are outside the shape and values > 0 are inside the shape. When rendering, this information is read from
Recommends Tano · 2014-02 · Stack Overflow · on “How to design a game for multiple resolutions?”
For example, text starts to look horrible when scaled down. Don't use textures for text. Use a technique like signed distance fields [this video] for rendering clear text at any resolution. For artwork, the ideal would be to have resolution specific artwork for a variety of common resolutions / DPIs. Failing that, mipmaps will drastically improve the quality of the rendered texture if it's scaled down from the source texture image. It also might be easier to work the problem if you stop using pixel coordinates to do stuff. The default OpenGL screen coordinates are (-1,-1) lower left to (1,1) upper right. However, you can alter these using an ortho transform to account for aspect ratio like this c
Recommends Computer says 'no'--SOooooo · 2014-08 · Stack Overflow · on “What is state-of-the-art for text rendering in OpenGL as of version 4.1?”
I'm surprised Mark Kilgard's baby, NV_path_rendering (NVpr), was not mentioned by any of the above. Although its goals are more general than font rendering, it can also render text from fonts and with kerning. It doesn't even require OpenGL 4.1, but it is a vendor/Nvidia-only extension at the moment. It basically turns fonts into paths using glPathGlyphsNV which depends on the freetype2 library to get the metrics, etc. Then you can also access the kerning info with glGetPathSpacingNV and use NVpr's general path rendering mechanism to display text from using the path-"converted" fonts. (I put that in quotes, because there's no real conversion, the curves are used as is.) The recorded demo for
Recommends wondra · 2014-09 · Game Development Stack Exchange · on “Optimizing Texture Text Rendering?”
You dont actually need high resolution textures to renter text of any size, see valve's method here [LINK] or here [this video] .
Recommends David Gouveia · 2019-11 · Game Development Stack Exchange · on “How can I create good looking football field lines?”
There's a cool way to render crisp lines and contours using small resolution textures! I usually see it being called Signed Distance Field Text Rendering - it's what TextMeshPro uses - but there's nothing stopping the technique from being used for other purposes. The general idea is that you pre-process the texture in a special way so that each pixel stores the distance to the closest edge (0.5 for pixels right on the edge, with the value going to 0.0 outside the shape and 1.0 inside). This ends up looking a bit like a blurry version of the original texture. But when you render that texture using a special shader (which I belive in its simplest form only needs to do something like output.a =
Cites eav db · 2016-11 · Stack Overflow · on “Rendering Text with Signed Distance Fields in WebGL”
Core Problem: I want to render Text in WebGL. I don't want to do this via an "overlayed" HTML DOM Element. I want the actual text rendering to happen inside WebGL. Initial Solution 1 Render each character as a high number of quads. This is not good as I need to render many characters. Initial Solution 2 (implemented + tried this one). Using Canvas, render all characters into an "atlas/map". Convert Canvas into a WebGL Texture. When I need to render a character, just pull it from the Texture. Problem: Even if the Canvas renders the font at font size 80, and the WebGL renders the font at font size 20, it's still blurry due to various forms of antialiasing, interpolation, and whatever else post
Cites Vertexwahn · 2017-01 · Stack Overflow · on “Drawing text to a 2D texture in DirectX 11?”
I guess the cube textures do not change too frequently, since the language should not be switched to often by the user. In this case I would use a toolkit like Qt to generate the textures - similar like this: QImage image(width,height,QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter painter; painter.begin(&image); painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing); painter.setFont(font); painter.setPen(Qt::black); painter.drawText(0, metric.ascent(), QString(c)); painter.end(); To access the texture data: auto* data = image.data(); A different solution would be to use Signed Distance Text Rendering [this video] . Doing this you need to render this
Cites Kuba hasn't forgotten Monica · 2017-05 · Stack Overflow · on “How do hardware-accelerated toolkits like Qt & JavaFX enable quality font rendering?”
All text rendering in Qt 5, so far, always starts with the CPU-based raster backend. In Qt 5, there are three text rendering modes: QWidget - raster backend output is used directly, there's no hardware acceleration. QOpenGLWidget - the raster backend renders to a texture (perhaps a font atlas [LINK] ), the texture is then displayed on triangles. Zooming in causes obvious pixellation. Qt Quick (in QML) uses Valve's Signed Distance Field [this video] text rendering, and is done on the GPU based on a precomputed distance field texture. The texture comes from the raster backend, but doesn't directly represent the text you see. The SDF representation allows cheap text styling - outlines, glows and dro
Cites Kleber · 2017-06 · Stack Overflow · on “How to align multiple objects in Unity (with or without code)?”
For Text Elements, there are two options to make them follow a particular GameObject in the world: You can create a Canvas with Render Mode set to World Space , like this: [LINK] You can use the TextMesh Pro [LINK] (now Free) and use it's TextMeshPro component: [LINK] I rather use the second solution since you don't have to create a Canvas to fit your simple component TextMesh Pro is really great for any size of fonts since it uses Signed Distance Field Fonts [this video] . But if you want the text always face the player camera, you have to implement a Billboard, which may have the same impact as your initial script public class Billboard : MonoBehaviour { private void Update() { transform.forwar