Dev Blog: Alpha Outlines
Timothy
Hey guys,
In this blog post we are going to take a look at the use of alpha, and the horrible artifacts that can occur in it’s implementation. There are a wide variety of shaders that utilize the alpha channel of a texture to create transparent objects. These can range from glass to grass, but we are focusing mainly on how alpha can get those garish white or black outlines even though the alpha channel is crystal clear.
The problem lies essentially in mipmapping, which is texture LoDing (Level of detail) using texture compression. So we need to understand that when the texture is compressed or mipmapped, the texture is changed from how one painted it. This is effectively rescaling the image and blurring the alpha.
Suddenly the texture that was once saying only show the nice tree leaves, is now telling the shader to show a slightly larger outline around the shape, due to the blurring of the texture. There are few options available here.
-
Don’t use mipmaps and texture compression (such as disabling them in unity).
-
Paint your own mip maps.
-
Paint an average approximation of the colour filling the rest of the texture.
By far the easiest and quickest solution is to fill the background of the image with a colour close to the borders of your image.
Alpha can cause a lot of annoying little problems, and I see this one pop up all the time. I hope it can help you guys out and if you have any tips for working with Alpha images, leave a comment.