Distance Map Generator

a Unity tool

Sun, 19 Feb 2012 13:22:00 +0000

I have released a neat little tool for Unity. It's a distance map generator that's available right inside Unity's editor. You can access it through scripting as well.


distance map generator inside Unity

What's the use?

Distance maps are useful when you want to display a texture with sharp contours in it and want it to look good when magnified. Bitmap text a prime example.


alpha blending and testing with regular font atlas

Using a distance map and the right shaders, you can get nice looking edges even when zoomed in a lot. You can also add effects like outlines, glows, and shadows.


distance map with smooth edges, outline, and shadow

Note that a thin font with sharp edges, like Times New Roman that I used here, is especially nasty to magnify.

What's special about it?

I'm not the first to make a distance map generator, even for Unity. What's good about this one is that is produces very good distance maps from low-resolution anti-aliased textures. Basically, any plain font atlas will do. In contrast, most naive approaches requires high-resolution bitmaps without anti-aliasing. It's also really fast too.

I did not invent this stuff, I merely ported it to C# and made a nice Unity editor for it. The algorithm used by the generator is the anti-aliased Euclidean distance transform described by Stefan Gustavson and Robin Strand. See here and here for further information.

Where to get it?

You can find the tool and its documentation here. It's available for free under the GNU GLP.

Why did I make it?

I made the generator because it's very useful for a text tool I'm going to release in the near future. Basically, it's the ultimate Unity solution for displaying text. Check out its Unity / Works In Progress topic if you're interested.


40 + 2
Website (it's a trap)