惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
罗磊的独立博客
月光博客
月光博客
GbyAI
GbyAI
腾讯CDC
G
Google Developers Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
雷峰网
雷峰网
B
Blog RSS Feed
美团技术团队
M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
D
Docker

Red Blob Games: latest blog posts

Red Blob Games: English: a vs an Red Blob Games: Differential heuristics Red Blob Games: Responsive design calculator Red Blob Games: Academic citations Red Blob Games: Highlighting interactive code blocks Red Blob Games: Optimizing page size Red Blob Games: Writing a guide to SDF fonts Red Blob Games: URLs with trailing punctuation Red Blob Games: What I did in 2025 Red Blob Games: Goodbye Sass Goodbye Sass Red Blob Games: RotMG map seeds Red Blob Games: Mapgen4 Mapgen4's use of WebGL2 Red Blob Games: Mapgen4 river shader Red Blob Games: Mapgen4 renderer Red Blob Games: Harnessing ChatGPT hallucinations Red Blob Games: Let Let's write a search engine, part 2 of 2 Red Blob Games: Let Let's write a search engine, part 1 of 2 Red Blob Games: Hexagon conversions Red Blob Games: Mapgen4 trade routes Red Blob Games: De-optimizing mapgen4 Red Blob Games: Hexagon spiral coordinates Red Blob Games: Thoughts on Flash Red Blob Games: What I did in 2024 Red Blob Games: Hexagon page animations Red Blob Games: SDF Halos SDF Halos
Red Blob Games: SDF headless tests, part 1
2024-11-09 · via Red Blob Games: latest blog posts

In the last few posts I have shown some of the experiments I did with font rendering. Those experiments were all in the renderer. I’m using msdfgen-atlas to generate the textures used by the renderer, and I wanted to experiment with msdfgen’s parameters. Instead of generating new font data and then reloading the browser, I decided to try “headless” rendering controlled by a shell script.

Testing with different parameters

In my blog post about antialiasing I found that instead of changing a slider, I wanted to see the entire range of outputs at once. I did that here as well. For each parameter value I ran msdfgen and generated an output file. Then I compared all the output files against each other to learn about the effect of each parameter.

Getting my code running in stackgl/headless-gl took a lot of work. My code wasn’t designed to work headlessly. But I also had trouble with the installation process (which needs python?!) and poor interactions with twgl.js not liking headless-gl. I’m not sure what to think of this. Is there another headless gl library I should use? Or maybe I can use gl in the browser, with the File API to save the output to files? Or maybe Electron/Tauri? I was frustrated the whole time, and didn’t take good notes on what went wrong. I should have stopped, taken a break, and evaluated the situation with a level head. But instead I kept pushing through with tweaks and fixes until I got something running. [*Update* maybe I should look at Puppeteer[1].]

In any case, I did get something running, and here are some findings—

The first thing I wanted to test was the effect of the emrange / pxrange parameter.

for test in 1 2 3 4 5 6 7 8 9
do
    ~/Projects/src/msdf-atlas-gen/bin/msdf-atlas-gen \
        -type mtsdf -emrange 0.$test -dimensions 511 511 \
        -font ~/Library/Fonts/FiraSans-Regular.otf \
        -imageout assets/FiraSans-Regular.png \
        -json assets/FiraSans-Regular.json
    node msdfgen-parameters.js
    cp _output.png output/test-emrange-$test.png
done
emrange from 0.1 to 0.9

There’s a lot going on here!

Columns 1 and 2 show that the emrange affects how far out I can draw a halo. The other columns show that when I extend emrange to be higher, the font quality degrades.

Columns 3 through 6 should look the same in every row (except for font quality). But they don’t. The outline thickness changes (see column 4), the font thickness changes (see column 5), and the drop shadow distance changes (see column 6). That means there are bugs in my rendering code. If I hadn’t run this test, I might not have found them.

I thought about these bugs for a while and realized:

emrange affects the slope

The emrange affects the slope of the mapping from distance to the value in the texture. My shader was using the y value, the encoded sdf. But I want be using the x value, the distance value. After I understood what I did wrong, I was able to fix the bugs. The outline thickness, font thickness, and drop shadow distance are now consistent:

fix outline and font thickness to handle emrange

While going through these tests, I found and fixed several other bugs, including how I was using msdf+sdf for outlines and how my drop shadow shader worked.

I’m glad I worked on this headless rendering test, but I had enough trouble making my code working headless that I want to look for an easier approach next time.

In the next post I explored the asymmetric version of emrange.