TGA's or PNG's, which does Unity prefer alpha wise - which is more efficient?

I have some assets which in theory could share the same texture, which I would presume would be more efficient. The problem is I’m using PNG’s and you can’t (afaik) seperate the alpha from them like you can do with say TGA’s. With TGA’s they have an actual alpha channel meaning that in Unity I could simply create 2 materials, one with a diffuse shader (which would use the whole image and ignore the aplha channel) and the other with a transparent shader (using the alpha channel) but BOTH sharing the same texture.

So my question, are TGA’s less/more/the same efficiency wise as PNG’s? Or is one better than the other?

Any advice greatly appreciated.

All image files are compressed into another format on import so the source file should be in the format that best suits your needs. PNGs are a lousy way to go for alphas so use TGA, TIFF, PSD, etc that has better support for alpha channels.

What Ethan said.

In general, source file format absolutely does not matter for efficiency. You can use PSD, TIFF, PNG or anything Unity understands - the actual resulting texture will be completely identical in-game if the image is the same and you use the same import settings. Same with meshes, etc.

I have found out that the effects like drop shadows (Photoshop) in textures looks different if it’s imported using PNG or PSD. If PSD is used the drop shadow actually looks more like white halo than what I’ll get using PNG (i.e. the darker shadow effect). Is this know feature or should I submit bug report or something?

This has to do with how photoshop saves the file. Don’t save PSD as a layer with transparency. Create a separate alpha channel and if the drop shadow is black use a black background.

Basically photoshop saves transparent layers with white matte and you would need a black matte, there is no way to change this (as far as I know), though it would make sense to allow users to change this.

There is also a script called NiceAlphaUtility which takes care of this for you, but it’s a pain updating files, since you have to throw the texture into the utility each time you update it.

Either way there is an extra step to get pixel perfect PSDs into Unity.

As far as alpha support in general (besides Unity): PNG is better at cross platform than TGA (mac-pc, I had trouble getting tgas showing on a mac). TGA seems cleaner, but I have had so many issues with it in compositing that I now render to PNG when I want uncompressed with alpha.

For Unity I use PSDs, but mostly because I can’t control PNG alpha and I can’t get guaranteed TGA viewing on the mac. So it’s the lesser of three evils with the added benefit of having one file for both source and the actual project.

PSD is often best for transparency since you have complete control over the matte color for every pixel (as long as you use a real alpha channel rather than just transparency), whereas PNG only has a single matte color for the entire file. Although sometimes that’s sufficient.

–Eric

Is this your opinion, or is there a real reason behind your statement? As far as i know PNG is a lossless compression format. And should be as good as TGA.

Righto thanks guys, PSD’s for me then it seems!

The problem isn’t the compression, it’s the way the way alphas are stored in photoshop layers - photoshop’s a pretty lazy application in that regard and doesn’t properly clean up after itself, and hasn’t really caught up with the times in respect to widespread pre-multiplied alpha usage (ironic since Flash Fireworks both support it). TGA or PSD with specific alpha channels will give the most consistent results on all target platforms, and you don’t have to worry about the alpha being pre-multiplied - usually the cause for white/black halo/fringing people get on their sprites.

So it is just a problem when generating a PNG in Photoshop? Most of my images are created in Illustrator, so I’ll be fine?

@Tiles - PNGs are perfectly fine if you’re not using transparency/alpha. But when using just the transparency of a PNG file it is very hard to account for “bleed” so that often you will get unwanted artifacts at the transitions between transparent/opaque.

@gizmo1990 - This artifact issue also goes for PSD files that solely rely on layer transparency. Make sure to create a proper alpha channel. And as koyima pointed out it is best to use a method or plug-in that dilates the border of the transparent image to avoid any artifacts. My personal favorite is Flaming Pear’s Solidify plug-in:

http://www.flamingpear.com/download.html

The Solidify plug-in can be found in the “Free Plugins” bundle on that page.

Ah, i see. That kind of artifacts. The halo effect. But thats just true for PNGs created with Photoshop. I seem to remember that Photoshop fills the invisible parts with white colour. But i also think to remember that there is a solution for that.

PNG`s created with Gimp definitely keeps the colours in the invisible parts. They work just fine with transparency/alpha :slight_smile:

you have to make the last layer in Photoshop with a solid color or the transparency from the normal layers will overwrite your alpha…at least from my experience :slight_smile:
Gimp works like a charm here :slight_smile: