Readit News logoReadit News
Sharlin · a month ago
> 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!

taeric · a month ago
Yeah, I confess I would have assumed that this was more common than otherwise.

Makes me curious how much of computing is losing perceived speed because we have moved to calculating everything on the fly? Easy example is website layout. Yes, some dynamic sites need to calculate a ton on the fly. Most sites, though, probably don't need to reflow everything nearly as often as they do. And fitting everything into the mechanism that is the document flow remains baffling to me.

mr_toad · a month ago
> And conventionally conventionally, fonts were bitmaps in the first place!

Bitmaps in ROM on early machines.

https://en.wikipedia.org/wiki/Motorola_6845

estimator7292 · a month ago
Bitmaps in diode arrays on even earlier machines
bob1029 · a month ago
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/

eviks · a month ago
Thanks for the link, clicking around led to the discovery of this basic, yet fascinating 3D text demo

https://chlumsky.appspot.com/msdf-demo

jayd16 · a month ago
SDF is awesome but even then it's not a silver bullet. It's a raster technique and some people want vector fonts or subpixel rendering.
mfabbri77 · a month ago
I don't know how common it is in fonts, but for generic 2D vector graphics, problems arise from the management of self-intersections, i.e., the pixels where they fall. With an SDF rasterizer, how do you handle the pixel where two Bezier curves intersect in a fish-shaped path? For this reason, more conventional rasterizers with multisampling are often used, or rasterizers that calculate pixel coverage analytically, also finding intersections (sweepline, Bentley-Ottmann).
corysama · a month ago
I can imagine subpixel rendering being rather easy for SDF fonts. But, I can’t say I’ve seen it done.
9999_points · a month ago
This is "an entire doctoral research project in performant terminal emulation".

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

kaelwd · a month ago
The author of that issue has a whole video series about it: https://www.youtube.com/watch?v=hxM8QmyZXtg

A way faster terminal emulator demo: https://github.com/cmuratori/refterm

And a terminal rendering benchmark tool: https://github.com/cmuratori/termbench

6510 · a month ago
> What this code needs to do is extremely simple and it seems like it has been massively overcomplicated.
bardak · a month ago
I was wondering if Casey would end up a mention on this topic.
jiggawatts · a month ago
That really was just the most absurd argument for Microsoft developers to engage in. It felt like a parody of the "optimisation is unnecessary because us developers are such Prima Donnas and simply toooooo expensive to lower ourselves to such levels" attitude that some people have.

He used a cache. A simple hashtable. That's it. He got an absurd speedup of something like hundreds of times faster.

What are developers smoking these days that they can't even envision ever doing something like this without undertaking a research program?

To this day people will debate this, as if there's a valid debate to be had!

"No, no, no, it's premature to optimise software that is... being released to a billion users in production."

"Casey is adding unnecessary complexity that will be hard to maintain... by using a fraction of the code Microsoft did to solve the same problem."

"It must be full of errors... well... other than the superior Unicode compliance."

"It's so much longer to develop high-performance code... the evidence is that it took Casey two weekends to write a nearly complete terminal emulator!"

Etc...

Look where we are today. Microsoft still steadfastly refuses to even look at Casey's solution, let alone adopt it wholesale. Years later there are still blog articles being written about the performance issues of the Windows Terminal.

PS: Notepad and Calculator got the same "treatment" and now struggle to keep up with key presses.

krstffr · a month ago
This website almost crashed my m1 macbook pro (renders at 1 fps or something), so I guess point taken: rendering text is not simple!
wmanley · a month ago
Looks like it's caused by `backdrop-filter: blur(6px);` on `.menu-content`. After disabling that it's slow, but not that slow.

Edit: This is with Firefox 144 on Ubuntu 22.04

wmanley · a month ago
No, actually the biggest difference is removing the `filter` property from the `.wave2` class which is used for rendering the background. With that removed the page is responsive even with the backdrop-filter - and it makes no visual difference AFAICS.
wmanley · a month ago
It's also perfectly responsive if you disable JavaScript. Maybe something related to the --positionX and --positionY CSS variables that are updated on every mouse move?
dist-epoch · a month ago
And on my desktop, scrolling this page is painfully slow.

Author: frontend technical lead, setting high code standards

coxley · a month ago
> Author: frontend technical lead, setting high code standards

Haha, to be fair it's common to half-ass personal projects even if it's your primary domain.

eviks · a month ago
what's worse is that scrolling doesn't actually work unless you have the text area focused/under the wheel... very weird. Which is even worse for PgUp/Down as who would think to focus the area first for scrolling???
jeffbee · a month ago
With what browser? Seems fine with Chrome.
unwind · a month ago
Meta: this is kind of a repost, not even a month since last time [1].

[1]: https://news.ycombinator.com/item?id=45580559

henning · a month ago
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.
rhdunn · a month ago
Here's Sabastian Lague's (Coding Adventure) video on font rendering -- https://www.youtube.com/watch?v=SO83KQuuZvg.