Search Unity

Unity Signed DIstance Field Textures

Discussion in 'Made With Unity' started by Tim-C, Sep 23, 2010.

  1. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    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.


    screenshot20100924at804.png
    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!
     
    Last edited by a moderator: Dec 8, 2015
    Andy-Korth likes this.
  2. maxfax2009

    maxfax2009

    Joined:
    Feb 4, 2009
    Posts:
    410
    Hi

    You are just a rock star :) ACE
     
  3. theBrandonWu

    theBrandonWu

    Joined:
    Sep 3, 2009
    Posts:
    244
    Last edited: Mar 13, 2012
  4. Farbs

    Farbs

    Joined:
    Apr 28, 2009
    Posts:
    1
    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.
     
  5. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    You sir, are a smart cookie.
     
  6. Geenz

    Geenz

    Joined:
    Sep 1, 2010
    Posts:
    99
    UDK uses this technique to filter it's dominant light maps.
     
  7. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    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.
     
  8. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    268
    Wow! That is all :)

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

    WarpedAxiom

    Joined:
    Oct 27, 2006
    Posts:
    245
    Amazingly useful.
     
  10. Timmey

    Timmey

    Joined:
    Apr 13, 2010
    Posts:
    35
    This should help get rid of the annoying blurriness associated with 3D text.

    neat :!: :!: :!:
     
  11. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    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.
     
  12. WarpedAxiom

    WarpedAxiom

    Joined:
    Oct 27, 2006
    Posts:
    245
    How's this coming along? I'm anxious to try it out for myself.
     
  13. Vincent Pride

    Vincent Pride

    Joined:
    Oct 6, 2010
    Posts:
    39
    couldn't it be used for cartoony diffuse textures as well? (so all the art in the game could be produced from vector sources)
     
  14. Matt_001

    Matt_001

    Joined:
    Sep 17, 2010
    Posts:
    101
    Really interesting, it may solve my current custom font problem!
     
  15. Timmey

    Timmey

    Joined:
    Apr 13, 2010
    Posts:
    35
    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.
     
  16. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Any movement on this? Was it released and then pulled or something?
     
  17. Matt_001

    Matt_001

    Joined:
    Sep 17, 2010
    Posts:
    101
    I believe the author will, for sure, warn us when the release will be ready.
     
  18. Dev.D1

    Dev.D1

    Joined:
    Dec 29, 2010
    Posts:
    99
    @Stramit: Sorry for the grave dig but do you have a workable version of your awesome tool ?
     
  19. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Yes, is this tool available somewhere?

    Thanks
     
  20. imggames

    imggames

    Joined:
    Aug 18, 2012
    Posts:
    22
  21. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Here is a link to TextMesh Pro, a tool I have been working on which leverages the awesome power of distance field text rendering.
     
  22. Erind

    Erind

    Joined:
    Jul 23, 2014
    Posts:
    56
    Last edited: Dec 8, 2015
    IzzySoft likes this.
  23. Erind

    Erind

    Joined:
    Jul 23, 2014
    Posts:
    56
  24. unity_6JNEIMz5dCgeLQ

    unity_6JNEIMz5dCgeLQ

    Joined:
    Mar 6, 2019
    Posts:
    1
    The link for the paper is not working could you please update it.
     
  25. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723