Top
Best
New

Posted by ibobev 9 hours ago

SDF vs. MSDF vs. Slug: GPU Text Rendering(alphapixeldev.com)
117 points | 48 commentspage 2
jayd16 7 hours ago|
Is there a runtime comparison of the shaders needed? Seems like you might have to do a lot of texture sampling if you have to walk the ray through the data but maybe there's a trick?

MSDF is pretty much just the target texel in question plus the surrounding samples in a way the GPU can do entirely upfront before the math starts. (M)SDF glyphs also play nicely with mip mapping and I would think this Slug algorithm needs uncompressed data. Maybe that doesn't matter because you just don't scale the data ever?

flohofwoe 6 hours ago|
Slug doesn't use "bitmap" font data but more like parameter lookup tables in storage buffers, pre-processed from TTF files. The lookup data can of course also live in textures (so that it works in WebGL), but using those textures as "poor-man's storage buffers", e.g. fetching the data directly without filtering.

The pixel shader is indeed quite complex compared to SDF:

https://github.com/floooh/sokol-samples/blob/8afa83928ce1870...

rezmason 8 hours ago||
Slug looks impressive!

The project I'm most known for is basically an MSDF shader with a bloom pass. It serves my needs 100%, though if I expand to support arbitrary text, I may reach for Slug.

The one issue with MSDF I want to raise is, it seems everybody uses the same msdfgen texture creation program from Viktor Chlumský's master's thesis 11 years ago. I wish there were other implementations. Who ever heard of a graphics technique that was only ever programmed once, and then used everywhere without substantial iteration? We need to de-XKCD-2347 MSDFs for everyone's sake, including and especially Chlumský.

torginus 7 hours ago|
I haven't heard of Chlumský or MSDF before, but I think a lot of people have been aware of the technique before he published his paper, thanks to Valve's TF2 text rendering paper:

https://web.archive.org/web/20120505013814/https://www.valve...

The pdf details only simple SDF, but in the closing paragraphs, it mentions the weakness of the technique and mentions how it can be solved with multiple SDFs, but the exact technique wasn't showcased.

Which led to people trying to reverse engineering it, and making their implementation, for years (it's Valve after all). Including me. Not sure if what I came up with was exactly MSDF, but certainly there are a lot of implementations out there.

rezmason 7 hours ago||
We mostly agree! I should elaborate.

I'd say what you and the others did was research, not implementation. Your results were solutions to the same problem, not variations of the same recipe. What you did is important but separate from what's concerned me.

A recipe of Chlumský's— the msdfgen utility— is widely used, but only has one producer. I'm just saying that that's a liability. Like, imagine if HarfBuzz was the only text shaper, and was maintained by one person.

sirwhinesalot 7 hours ago||
There's another GPU text rendering algorithm missing from the comparison: Rook & Possum's Scanline Sweeper:

https://rookandpossum.com/posts/scanline-sweeper/

Sean Barret (creator of the stb public domain libraries) independently invented a CPU-based implementation of the same idea, used in stb_truetype.

logdahl 7 hours ago||
I knew the second Eric posted about releasing Slug to the public domain we'd get 100s of "OpenSlug" slopped-up. Will be interesting to see which implementation will win or if Slug will keep being a thing.
flohofwoe 7 hours ago|
Tbf, the Github repo doesn't look particularly 'sloppy' to me, more like some mild AI assistance. There's several months of fairly regular looking git history, a couple of commits with an LLM disclaimer for python bindings, and two llm-context files.

https://github.com/AlphaPixel/slughorn

bel8 8 hours ago||
MSDF looks better than Slug for me in the first example.

But slug wins in perspective in my eyes.

I use MSDF to render crisp text in my webgl hobby game. Hope to publish it with source code when I get the time.

thanks for sharing the article. I'll take a deeper look at it later.

Keyframe 8 hours ago||
I do MSDF as well and since I'm not doing a huge-ass text editor (and even then) it works and it's great. One thing to consider is that with any solution that does things directly from vector outlines means you also then have to distribute proper font outlines and you might not have a license to do that. With MSDF and similar atlas-like solutions, you pre-render a font and distribute that rendered image instead of an actual font.
dcrazy 7 hours ago||
Which you also might not have the license to do. I once licensed a Monotype typeface that prohibited its use in anything editable, including fillable PDF forms.
__m 8 hours ago||
[dead]
hncbw02z5a 8 hours ago||
MSDF corners gave me trouble til I bumped the distance range at small sizes.
LoganDark 3 hours ago||
> By Chris Hanson

What a name!

(Skipped the rest of the article cause it's AI.)

reactordev 8 hours ago||
Excellent write up. The cited references are on point too. Eric Lengyel is a legend.
sophietaylor 6 hours ago|
[dead]