I took a break today from working on the Strumpy Shader Editor to play with something that has been frustrating my in unity for quite some time. Do you ever want to have nice outlines, or funky effects on your fonts / decals, but find it really hard and frustrating to do?
This is where signed distance fields come in. They offer an alternative way of storing binary (on or off like a font) data in a texture. Instead of storing if a pixel is ‘on or off’ a signed distance field stores the distance from the pixel currently being examined to the closest pixel of the other color. By doing this you end up with a field that describes relative distances in a texture. By taking advantage of the linear sampler in the video card it is possible for a sign distance field texture to still look good, even at low resolutions!
This texture is then input into a shader that clips the values on the edge that fall below a certain threshold. In this example we do a bit more fancy shader work and actually add an outline:
The great thing about this technique is that it will work for things like texture sheets, shadowmaps and a great many other binary representations. This will allow for memory savings, increased quality (at the same resolution), and better representation of binary data.
At the moment I’m writing a font fx package that auto generates sign distance field fonts from the unity ttf imports, and a selection of FX shaders to go with them. I just need to fix up some AA stuff. I should release it in the next few days. Nice fonts… here we come!
I reckon people would get a kick out of a demo shader that used this to “grow” letters over time by adjusting the test value. Better yet, you could build a slightly more advanced shader that grew the text across time and space, appearing first from the left or right side.
First post Been looking for something to make better fonts, thought I found something with http://www.youtube.com/watch?v=vtBV27yWUYA but he doesnt mention anything about releasing the code, so looking forward to trying your system. Will your system adjust kerning etc when a border is added?
Mike
Edit: Doh silly me, it isnt a font system is it Sorry ignore the question, looks great though still wnt to give it a go.
Thanks having a look at this everyone. I don’t have the release ready yet due to an impromptu trip to Sydney for a Masquerade ball (it was ace), and I didn’t have my laptop with me. Ill be putting together a package for download early this week.
That it does. It’s a great way of encoding binary data and I sense that there will be a lot of movement towards the technique in the next year.