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

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
J
Java Code Geeks
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
Google DeepMind News
Google DeepMind News
小众软件
小众软件
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
B
Blog

Red Blob Games: latest blog posts

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 2
Red Blob Games: Distance field effects
2024-03-28 · via Red Blob Games: latest blog posts
Blog post: 27 Mar 2024

In the last post I described how I fell into the font rendering rabbit hole. I try to put some time limits on each topic — otherwise I would explore forever! I try to pick a theme each week:

  • Week 3 was the basics: SDF, MSDF, atlas, shader
  • Week 4 was effects on individual glyphs: outlines, shadows, glow, bevel
  • Week 5 was effects on how glyphs move: sink, rise, bold, slant, rotate, wavy, bounce, warp

The key idea I wanted to explore this week is that a distance field font can be thought of as contour lines:

Contour line representation of a glyph

When rendering a font normally like I did last week, I considered distance < 0 ? "white" : "transparent". But there are so many more things to do with this distance!

The first thing I wanted to do is outlines. This is roughly distance < 0 ? "white" : distance < 0.1 ? "black" : "transparent":

Font rendering with outline

I think this looks beautiful!

A variant is to apply blur to make this into a shadow, or apply blur and a bright color to make it into a glow effect. But I noticed that MSDF vs SDF makes a difference. SDF produces rounded corners, and I think the outlines don’t look nearly as good as with MSDF:

Font rendering with outline

I wanted to see the difference, so I made this to highlight the pixels where they were different:

Round vs sharp shapes

For some effects like shadow and blur I wanted the rounded corners, and for others like outlines I wanted the sharp corners. So I experimented with using both.

I played with lots of other things too, including taking the gradient of the distance field to get angles:

Visualization of angles

This gave me a way to apply lighting and make a bevel effect.

I learned a lot in Week 4. I had lots of bugs and I generally found it hard to debug shaders compared to cpu code. Sometimes I didn’t have the right frame of mind to fix a bug, so I continued with other experiments until I had a new idea, then came back to the bug and fixed it. I wrote up my notes originally for myself, and then cleaned them up for sharing. I had more I wanted to do, but the week was over, so I wrapped up and moved on to the next topic in Week 5.