PNG files, alpha, and Photoshop
Regarding the PNG’s not supporting alpha properly…
It is my understanding that the problem is specifically a Photoshop bug, and not actually a problem due to the PNG format itself. It is possible, using software other than Photoshop, to produce a PNG with an alpha that works exactly the same way as a TGA’s alpha. Most compositing programs, such as Nuke, handle PNGs with alpha just fine. In those programs, you can throw any information you like into the PNG alpha channel, and not risk loosing either the alpha or color information.
However, opening a PNG file in Photoshop, that has color patches where the alpha is black, will result in a loss of those areas of color, when you save the file back out. Saving any PNG from Photoshop causes similar problems. (See more technical info below if interested.)
Because Photoshop is such a staple in the industry, the best course of action for working with Photoshop and widely supported image formats for games seems to be, if you want low disk space size of source art:
-PNG files for images without an alpha channel
-TGA files for images with an alpha channel
(TIFF has reasonably wide support as well, and has better compression than TGA but not as good as PNG)
Here’s a visual demonstration of the problem, with images you can download to test yourself if you like:
://www.teaching3d/examples/png_bug_from_photoshop/
and the actual demo image:
://www.teaching3d/examples/png_bug_from_photoshop/image_comparison_of_color_and_alpha_channels_in_png.jpg
Additional technical information:
Essentially the problem comes down to the fact that you have no way of controlling the color channel information that gets saved into fully transparent pixels in Photoshop. Photoshop, unlike most high end compositing software, internally treats transparency as something different than alpha. Photoshop will fill the color channel with white in most places where the alpha is black. (I think it’s likely that this is because Photoshop still assumes it is working on “white” paper, so instead of empty transparent pixels being black in the color channels, they are white, there, instead.)
Normally, the primary reason to use a PNG instead of a TGA, is that the PNG images are drastically smaller on disk, so the source art is more efficient even if the in-engine art is the same size (eg in texture memory). In cases where textures have any chunks of solid color in any of the channels, or certain types of gradients, the file size on disk difference can be huge. It is quite dependent on the visual content of the image.
When using other software together with Photoshop the I’ve written custom code to fix this problem. The resulting PNGs will work fine in many programs, but not in Photoshop, and unfortunately, not in Unreal 4 either. In my opinion it’s a bug in both Photoshop and Unreal 4, probably not noticed because so many users of Unreal 4 use Photoshop. (I say bug in Unreal 4 because it looses information that I can prove is present in the same PNG file by opening it in other viewers.)
Adobe seems to have no plans to fix the problem, even though game artists have known about this and complained about it for the past 15 years. Open EXR had the same problem when it was introduced, but enough people complained and now you get a choice as to how Photoshop should function when you open an EXR with an alpha channel.