Hello again :3
This shader will be extremely useful to you guys who are designing elements for your game that need to scale up (such as HUD elements, stencil shapes, and glyphs), but don't want to waste lots of disk space or texture memory to store super-high resolution versions of the elements. The algorithm is based on a technique used extensively in Valve's TF2 game for stenciled graphics and described in further detail here.
How it works: A distance map is 'baked' inside the alpha channel, which when a threshold filter is applied to, gives a crisp outline for the texture. Since the GPU upscales using bilinear filtering, nearby pixels are used to smoothly interpolate the distance value automatically, at virtually no cost. A smoothstep() function is used to further improve the effect by taking the resulting outline's alpha value and interpolating slight variations of the threshold value against the distance map.
I've taken the basic premise behind the algorithm and incorporated it into an HLSL shader. Right now, the only parameter that is possible to alter is the threshold level, which allows for a bit of fudge factor when creating the distance maps manually in Photoshop rather than writing a program to generate the maps automatically. Because Photoshop messes with the curves when in Grayscale mode, this might produce some unexpected results when working in (or converting to) grayscale. I'm not sure if this can be fixed with an appropriate color profile, but the effect seems to avoid being munged when it's stored in the alpha channel. Later on, I might implement some of the other tricks Valve suggested in the paper, such as Drop Shadow and Outer Glow, directly into this shader.
How to create a distance map:
First, you need a crisp outline at a large resolution of the image you wish to scale (I recommend at least 1024x1024). Preferably, the alpha channel is already loaded into photoshop, and not separate from the image. If they are separate, merge them so you have an alpha-blended image.
Now, clone the layer and add the following effects:
Size: 150 (Essentially, Width/8 with a little extra)
This will give us the distance map needed for the shader. Now, we need to copy it to the alpha channel. One way to do this is to go into Channels, and click the "Load Channel as Selection" button. From here, you have the alpha component as a selection. By clicking Select->Inverse and hitting the Del key on your RGB map, you should get something like this:
Now, simply scale it down to the size you want (I chose 128x128 for my example MFA), and import it into MMF and activate the shader. If you're lucky, you won't have to adjust the threshold level at all. However, if the outlines seem too small/large, simply adjust the threshold level using the parameter.
I've included an example with the shader to show that you can use this for multi-colored images, and not just stencils, but where this effect is most impressive is for things like HUDs, trees and foliage on multiple parallax scrolling layers, and especially text. You can get near-perfect scaling up to HD levels from a distance map as small as 64x64 (!), but you can go even smaller than that if you don't plan on scaling up too big (for example, resizing hud elements based on display resolution).
Enjoy! And, now that I think about it, wouldn't it be cool if Actives' "Anti-Alias" option actually did something like this in HWA automatically instead of what it does right now?