(More) Text Rendering Improvements

I took a short vacation last week and I spent some time reading about different topics. I came across a book titled OpenGL Insights which included a very educating chapter written by Stephan Gustavson about text rendering using signed distance fields. In his paper, Stephan proposes a different approach for computing the distance map:

The new antialiased Euclidean distance transform is a straightforward extension of traditional Euclidean distance transform algorithms, and for the purpose of 2D shape rendering, it is a much better fit than previous methods. It takes as its input an antialiased, area-sampled image of a shape, it computes the distance to the closest point on the underlying edge of the shape, and it allows fractional distances with arbitrary precision, limited only by the antialiasing accuracy of the input image

He also provided an implementation for the book using a 16-bit depth value for the depth map, which is a much accurate format than the one I use in my current implementation (8-bits). In addition, his fragment shader interpolates the distance value for every pixel and its neighbors, producing much better end results.

I’m currently in the process of enhancing my implementation based on Stephan’s approach. To be honest, I still don’t understand much of the algorithm, but so far the results are very promising:

Improved text rendering using antialiased Euclidean distance transform
Improved text rendering using antialiased Euclidean distance transform

Improved text rendering

Some time ago I talked about how Signed Distance Fields can greatly improve text rendering, but I noticed that my implementation was suffering from several visual artifacts. That was specially true when displaying small characters.

Then, I went back to the font generation tool and made some changes in order to remove those artifacts or at least reduce them as much as possible. In addition, the resulting textures are bigger and the SDF is much more precise.

Here’re two images comparing both implementations:

Before: notice the artifacts in some glyphs (i.e. the “D” in “Died”)
Now: artifacts are less noticeable
Now: artifacts are less noticeable

Also, I moved all the font atlas generation and SDF calculations to the main repository (they were separated projects before). That way it’s easier to use from within projects and I can take advantage of some tools already included in Crimild.