Home Technical Talk

Targa or png for unity

polycounter lvl 6
Offline / Send Message
Pinned
MITVIZ polycounter lvl 6
i am using speedtree to make trees but for their example trees they have all files in targa, well from my comparison targa files  are much larger than png files so why are they used? i am not clear about it so if anyone can clarify it that would be great thanks

Replies

  • kio
    Options
    Offline / Send Message
    kio polycounter lvl 16
    I think the main reason is that photoshop has pretty shitty handling of png transparency, as it does not keep the alpha channel explicitly. This is in no way a limitation of png, its more like an undesirable behaviour of photoshop :(

    but most of the time it doesnt matter, as images are composed and exported from another tool to png - and its not the intended workflow to edit the resulting images.

    for unity it doesnt really matter which source files you use for textures.



  • angelo9888
    Options
    Offline / Send Message
    angelo9888 vertex
    It doesn't matter what kind of file type you are using! Always go for the best uncompressed quality. Unity compresses them upon build anyways.
    For example if you have a 12mb png image and a 76mb targa no matter which one you choose the build size would be 4mb for both (the numbers are random) 
    I guess png would be fine though. The only difference is that targa is able to contain the alpha map for transparency.
  • Farfarer
    Options
    Offline / Send Message
    If you use SuperPNG with Photoshop you should be OK. Kio's right in that Photoshop's native handling of PNG is pretty damn rubbish. SuperPNG also supports 16bit PNG images, which is nice.

    http://www.fnordware.com/superpng/
  • defragger
    Options
    Offline / Send Message
    defragger sublime tool
    we use only png because we have a lot of textures. TGA would blow up our SVN.
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    aha, thanks guys! png it is then and targa if i want to keep the alpha maps but basically speedtree will optimise it anyway, hat's what i took from all this, thanks for super png! looks like something i should be using instead of normal png
  • Farfarer
    Options
    Offline / Send Message
    SuperPNG has control over the transparency/alpha of PNG on both load and save. You can tell it to treat the alpha channel as transparency or as alpha (the difference being that if it's transparency then all the pixels that are fully transparent have their colour optimised out for compression, so probably not the result you're after - alpha keeps the colour even if it's alpha value is 0).
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    well am not so specific quality, there can be small changes but i will definately give super png a go, just wondering why i see some many people using tga instead
  • Farfarer
    Options
    Offline / Send Message
    Mostly because it's a very simple (and very old) file format format with widespread support (although that does mean it's not as fully featured - 8bit only - and is usually uncompressed - large file size).
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    well for speedtree i have to save as 32 bits to keep the alpha part of it but i think for this project i am on the programmer will tell me what he prefers, i refered him to super png so lets see what is best before i start working on textures
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    just tried super png, it doesnt seem to save the alpha channel though and file size almost the same as a normal png
  • Farfarer
    Options
    Offline / Send Message
    Did you tell it to save the alpha channel? There's a pop up with options when you save.
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    yes i ticked it, then after reopened that same image in photoshop to see if the alpha channel was there and nothing
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    on purpose i used a image that had an alpha in the channels section also
  • RN
    Options
    Offline / Send Message
    RN sublime tool
    For Photoshop to export a transparent PNG the transparency needs to be in the layer itself (as transparent pixels), not as an alpha channel in the Channels tab. This means you should see a checkered background for the transparent parts.

    If you only have transparency as an alpha channel and you want to make a PNG, you need to convert that channel to transparent pixels in the layer. Go to the Channels tab and CTRL + click on the alpha channel (or select that channel and press the "Load As Selection" button) to load it as a selection, go back to the Layers tab and click on the "Add layer mask" button (it's a square with a hole on it), which will make a layer mask from the selection.
    Then you can save as a PNG straight away, or right-click the layer mask and select "Apply Layer Mask" to apply the mask directly as pixel transparency.

    To save the PNG with transparency, you can use...
    - File -> Save As (and choose PNG format), or
    - File -> Save For Web (and choose the PNG - 24 format) where you can explicitly tick the 'Transparency' option to export with transparency or if you don't, it flattens with a white background.

    PS: To make an alpha channel out of a transparent layer, select a layer and go to menu Layer -> Layer Mask -> From Transparency, it makes a layer mask from it and makes the layer pixels opaque (with bleeding and such).
    Then you can go to the Channels tab and duplicate the "Layer (n) Mask" channel or else when you delete the layer mask that temporary mask channel will also be removed. The duplicate stays there, and when you save it as a TGA it will be considered as the alpha channel (if you tick the Alpha Channels option in the Save As dialog, of course).
  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    "the programmer will tell me what he prefers"

    Make sure to fully test all the variables of the solution you end up going for, as this stuff goes much deeper than just "transparent or not". For instance in some circumstances you can end up with the transparent pixels being effectively deleted, which might not sound like a big deal at first but can bite you in the butt later. If you go for PNG, then at the very least use SuperPNG for maximum control.

    I'd personally always favor TGA if possible simply because it is raw and straightforward. It also saves really fast - I just ran a test recently, and saving 3 big folders from a 4k PSD to TGAs using an automated file saving script took 10 seconds, whereas the same thing with regular PNGs took over a minute. That's the kind of stuff I am talking about when suggesting you to test all variables of a given solution.

    In general you want to work in such a way that you the content creator can always access the fully editable source data, with all the conversions/compression being taken care of transparently later down the pipe. For instance the game might use some advance DXT compression, but you should never have to even worry about that (and this is where the Technical Artists/tool guys come into play). But of course this also all depends on team size.

    Good luck !
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    RN said:
    For Photoshop to export a transparent PNG the transparency needs to be in the layer itself (as transparent pixels), not as an alpha channel in the Channels tab. This means you should see a checkered background for the transparent parts.

    If you only have transparency as an alpha channel and you want to make a PNG, you need to convert that channel to transparent pixels in the layer. Go to the Channels tab and CTRL + click on the alpha channel (or select that channel and press the "Load As Selection" button) to load it as a selection, go back to the Layers tab and click on the "Add layer mask" button (it's a square with a hole on it), which will make a layer mask from the selection.
    Then you can save as a PNG straight away, or right-click the layer mask and select "Apply Layer Mask" to apply the mask directly as pixel transparency.

    To save the PNG with transparency, you can use...
    - File -> Save As (and choose PNG format), or
    - File -> Save For Web (and choose the PNG - 24 format) where you can explicitly tick the 'Transparency' option to export with transparency or if you don't, it flattens with a white background.

    PS: To make an alpha channel out of a transparent layer, select a layer and go to menu Layer -> Layer Mask -> From Transparency, it makes a layer mask from it and makes the layer pixels opaque (with bleeding and such).
    Then you can go to the Channels tab and duplicate the "Layer (n) Mask" channel or else when you delete the layer mask that temporary mask channel will also be removed. The duplicate stays there, and when you save it as a TGA it will be considered as the alpha channel (if you tick the Alpha Channels option in the Save As dialog, of course).
    Thanks for the advice, i know how to save png files but its super png am talking about, i was thinking when i make a save if i am using a png image with transparency and no alpha channel in the channels section it will automatically create an alpha channel for me so when i open it in photoshop i would see that extra layer either in the layers pallet or channels, so maybe i got it wrong what it does but for now am having the same result as if i save as regular png file
  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    SuperPNG doesn't change the PNG format specifications, it just saves files more efficiently than the default Photoshop implementation with a few more available options. PNGs do not support multiple layers.

    (So all that said ... you are now seeing why many people like to use TGAs. In practice it might not sound like a big difference, but being able to clearly see transparency as a channel in Photoshop with a guarantee that no pixels being ever "destroyed" in the saving process is a serious relief. Now of course in practice a pipeline can very well be established around the PNG format, but I personally feel like it's asking for trouble.)

    Ironically I am pretty sure that internally PNG is a regular RGBA format, with 4 distinct channels, but there are definitely optimisations going on during saving that affect what is "under the transparency". And if I remember correctly (based on a post by an Adobe engineer) the somewhat odd way Photoshop displays it is dictated by the format rules.

    So from there that leaves you with TGA (non destructive) or DDS (highly destructive), which explains why so many tools and artists rely on the (unfortunately heavy) TGA format. As said earlier it really shouldn't matter in the end because a solid pipeline would take whatever you give it (PSDs, TGAs) and then compresses it as needed to create the (most likely DDS) files actually used by the game at runtime, which is definitely not PNG anyways.
  • MITVIZ
    Options
    Offline / Send Message
    MITVIZ polycounter lvl 6
    yeah its been confirmed on my side too, to stick with the tga format, programmers say its easier and they are used to it
  • Eric Chadwick
    Options
    Offline / Send Message
    To be clear, DDS isn't destructive.

    DXT is the destructive, lossy compression format you're thinking of.

    DDS is merely a container, which can contain different types of compressed or non-compressed image data. 

    Another vote for TGA format over PNG, at least for game development use. Shaders typically don't work well with PNG since they usually need alpha as a separate channel. TGA gives you this.

    You can also use RLE compression for TGA which is a lossless compression. Basically blank or solid-color areas get compressed a lot.
  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
    Thanks for the clarification Eric !
  • 0xffff
    Options
    Offline / Send Message
    0xffff polycounter lvl 3
    Would not recommend PNG. It's a weird format, comparatively. 
Sign In or Register to comment.