Signed Distance Fields for Alpha Tested Magnification of Vector Textures

Member
Posts: 283
Joined: 2006.05
Post: #1
[Image: Comparison.png]

I needed a break from iPhone dev, and decided to have a go at making a tool that might be useful in the future. I'd been looking at this paper by Valve about using signed distance fields in an alpha channel. This has a few advantages over using traditional 'coverage' maps:

- Scales nicely when using bilinear filtering, to avoid the usual lumpy appearance
- A shader can be used to soften the edges, for an approximation of anti-aliasing
- Special effects (glow, outline, drop shadow etc.) can be added using shaders using the SDF data

The really nice thing is that even without shaders, it can fall back to using alpha testing and generally look nicer than if you'd just scaled down a mask.

This tool lets you create low resolution SDF images from high-res masks, and preview them in an OpenGL / GLSL example.

[Image: SDFToolSS1.png]
Download SDF Tool
Requires Intel Mac and Mac OS 10.6

Usage: Drag a high-resolution mask onto the window, then check the results by clicking Preview. Changes made to the options below should update automatically. Turn off preview mode and drag the image out of the window to get the SDF image.

Known issues: I think Quartz Composer is passing gamma-corrected values to the GLSL shader. I don't know how to fix this properly, but I've put a gamma correction node in to compensate. The value might be wrong on different systems, so if the SDF preview looks to be a different 'weight' to the coverage preview, that's why. You can try altering the value in the Gamma Adjust node (in the composition inside the bundle) to fix it.

Also, at the moment it ignores any alpha information in the input image. It'd be nice if it used that instead of luminance when it's present.

This was more of an exercise for me (my first time using NSOperationQueue and Quartz Composer and any kind of direct pixel manipulation really), but if any of you find a good use for it I'd love to know about it. Bug reports are also welcome.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #2
Looks great! Thanks for sharing, maximile. Grin I'll have to give this a try some time myself when I get a chance.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
Aww. Needs 10.6. I suppose I should upgrade some day. Rasp

I've been thinking about a similar technique for terrain rendering. A low resolution terrain mask and a little marching squares to vectorize it works very well gameplay wise. Rendering the terrain mask with just plain alpha testing looks like crap of course. Good to know the idea actually works and somebody has figured out the details. Heh.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Reflect a vector in relation to another vector ipeku 4 5,187 Dec 12, 2011 07:17 AM
Last Post: ipeku
  OpenGL Distance Optimizations merrill541 17 6,549 Oct 4, 2009 11:27 AM
Last Post: arekkusu
  Point distance attenuation with OGL-extension - how? mcMike 6 5,579 May 21, 2008 10:58 PM
Last Post: mcMike
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 5,961 Dec 8, 2007 02:06 PM
Last Post: Malarkey
  png without alpha fine, png with alpha, nothing dave05 6 6,679 Jun 11, 2005 10:31 AM
Last Post: dave05