16 comments

[ 4.1 ms ] story [ 55.8 ms ] thread
This website almost crashed my m1 macbook pro (renders at 1 fps or something), so I guess point taken: rendering text is not simple!
This is "an entire doctoral research project in performant terminal emulation".

https://github.com/microsoft/terminal/issues/10362#issuecomm...

I was wondering if Casey would end up a mention on this topic.
> What this code needs to do is extremely simple and it seems like it has been massively overcomplicated.
SDF seems to be one of the better solutions for text rendering.

Valve had this problem solved since 2007. I'd argue this technique is a big part of what gave TF2 its impressive visual style. That game ran at 100+ fps on hardware like the 8800GT at the time.

https://www.redblobgames.com/x/2403-distance-field-fonts/

Stupid question but what are the units used in the results tables??
I wonder how the GPU version is implemented. One quad and one texture draw per glyph sounds very not scalable, but one quad per terminal, one texture atlas and one shader to draw glyphs from the atlas already sounds much better.
A terminal maximized on my screen says:

    ~$ echo $((2 * LINES * COLUMNS)) triangles
    34272 triangles
That's nothing for a modern GPU. For example, this benchmark[1] says to expect on the order of 10-800 million tri/s. At the low end of that, you'd have a frame time of 3.427ms -- 292 fps.

The original Playstation could do 180 000 textured polygons per second[2], so it could've managed ~5 fps. Of course, you wouldn't render that many chars at its available output resolutions anyway. :)

[1] https://github.com/ctsilva/triangle-rendering-benchmarks#:~:... [2] https://en.wikipedia.org/wiki/PlayStation_technical_specific...

And another website made unusable thanks to inconsiderate use of javascript.
Caching the fonts to a texture atlas is not an unusual idea. https://github.com/memononen/fontstash is a well known example of this. Odin has a native port meant to work in conjunction with its bindings to NanoVG. The Odin code is coupled to stb_freetype.
> So I tried something unconventional: draw each character once, cache it as a texture, and then just copy those textures around.

That’s more like the most conventional way to draw characters ever. Nobody goes around rendering filled Béziers any more than absolutely necessary. And conventionally conventionally, fonts were bitmaps in the first place!