For pixels with partial alpha (0.001 – 0.999) we use the sign() function to simply turn that into 0 or 1 (if greater than 0). Obviously, this won’t work for sprites with completely transparent pixels in the *middle* of the image. The secret is to check the original pixel’s alpha component! If it’s not 0, we assume it’s part of the outline. That’s easy enough – but how do we determine if the output color for a pixel should be the texture, or a color value? Pixels that are 1 unit away from the edge of a sprite will become the outline by increasing their alpha to a non-zero value. Looking through the code, you can see that the outline is built by adding up the surrounding pixel’s alpha values. Gl_FragColor = (v_vColour * (1.0 - originAlpha)) + That means the image_blend parameter is the outline color. Only blend with the image_blend factor if the original alpha was 0. Combine the alpha from all surrounding textels.Īlpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord + offsetX).a) Īlpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord - offsetX).a) Īlpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord + offsetY).a) Īlpha += ceil(texture2D(gm_BaseTexture, v_vTexcoord - offsetY).a) You’ll note that there is no outline, just our little baddie, walking around.Ĭredit to Bruce Juice from Spriters Resource.įloat originAlpha = sign(texture2D(gm_BaseTexture, v_vTexcoord).a) Here is the original sprite sequence from the example above. Before continuing on, please check out Shaun’s outline shader tutorial as I won’t be going into the details of how that works. Where my work expands on Shauns is to offer the ability to customize the color of the outline rather than always assuming the outline should be black. I used his tutorial for the basics of the outline shader. In the example below, I’m dynamically rendering a magenta border around a familiar baddie from the SNES days!Ĭredit to Shaun Spalding who is doing some great Game Maker tutorials on his Youtube channel.
These “special enemies” drop extra loot but how could we render them differently for the user to easily tell they should be prioritized? Applying an outline, or stroke, to the sprite would be great! While cooking up a new feature for our forthcoming title, Dungeon Rustlers, we thought it may be handy to denote some enemies as special.