Revisiting Text

As I write this post I’m in the process of merging both desktop and mobile OpenGL renderers into a unified one that supports both platforms. Although this is still incomplete, I wanted to share some of its benefits and side effects in the meantime.

A while back I talked about how to render dynamic text in 3D using Signed Distance Fields (SDFs). It turns out that approach is way too expensive for mobile and it doesn’t really provide too much of an improvement in smaller screens. So, no SDF support means that we need to provide two different textures for each bitmap font (with and without SDF). If SDF is supported in the current platform (i.e. desktop), the SDF texture is used for rendering. Otherwise, we use the standard bitmap font without any fancy processing.

Current implementation provides Text and Font classes, but it relies on client code to specify which texture to use. At first it looks like a versatile feature, but it ends up being very cumbersome.

Instead, the changes I’m making make sure this decision is left to the engine. Then, if current platform supports SDF, it will construct Text objects with the appropriated texture and shader program automatically.

In practice, these changes lead to a cleaner code on the client side, which now is unaware of whether or not SDF is being used. Both textures still have to be provided, of course, yet only one of them will be actually used when the program runs.

That’s it for now, but I’m planning on sharing much more about the new renderer soon. Stay tuned.

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:

text_before

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.