Signed Distance Fields for Alpha Tested Magnification of Vector Textures - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Signed Distance Fields for Alpha Tested Magnification of Vector Textures (/thread-205.html)
Signed Distance Fields for Alpha Tested Magnification of Vector Textures - maximile - Mar 29, 2010 09:08 AM
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.
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.
Signed Distance Fields for Alpha Tested Magnification of Vector Textures - AnotherJake - Mar 29, 2010 09:45 AM
Looks great! Thanks for sharing, maximile. I'll have to give this a try some time myself when I get a chance.
Signed Distance Fields for Alpha Tested Magnification of Vector Textures - Skorche - Mar 29, 2010 10:59 AM
Aww. Needs 10.6. I suppose I should upgrade some day.
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.