Unity Signed DIstance Field Textures

Hi,

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!

The paper that describes how to generate signed distance fields is here:
http://www.lems.brown.edu/vision/people/leymarie/Refs/CompVision/DT/DTpaper.pdf <-Seriously dense / maths based paper, for a relatively simple algorithm
And how these fields can be used in games (by Chris Green from Valve), here:
http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf

The little utility I wrote takes a black and white texture (not greyscale) and turns it into a signed distance field.


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!

1 Like

Hi

You are just a rock star :slight_smile: ACE

can’t wait for this to happen. Dealing with text/font in Unity3D is painful. This is much needed! Thanks!

Nice!

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.

You sir, are a smart cookie.

UDK uses this technique to filter it’s dominant light maps.

First post :slight_smile: 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 :slight_smile: Sorry ignore the question, looks great though still wnt to give it a go.

Wow! That is all :slight_smile:

Seriously I think your gonna make a lot of people happy with this!

Amazingly useful.

This should help get rid of the annoying blurriness associated with 3D text.

neat :!: :!: :!:

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.

How’s this coming along? I’m anxious to try it out for myself.

couldn’t it be used for cartoony diffuse textures as well? (so all the art in the game could be produced from vector sources)

Really interesting, it may solve my current custom font problem!

This is going to be a sweet system if it comes out. If it doesn’t I think I may try to make something similar eventually.

Any movement on this? Was it released and then pulled or something?

I believe the author will, for sure, warn us when the release will be ready.

@Stramit: Sorry for the grave dig but do you have a workable version of your awesome tool ?

Yes, is this tool available somewhere?

Thanks

http://forum.unity3d.com/threads/147935-VFont-1.0-is-available-on-AssetStore