Search Unity

PNG to TGA: remove artifacts from the transparent textures.

Discussion in 'Assets and Asset Store' started by AShim, May 20, 2012.

  1. AShim

    AShim

    Joined:
    Sep 24, 2009
    Posts:
    8
    This utility converts PNG file with transparency to 32bits TGA file (RGBA).

    WHY IS IT USEFUL:
    Unity converts all images into its own format.
    There is a white border on the translucent parts when Unity imports PSD image (1_PSD screenshot).


    If PNG image has transparency then Unity generates RGB components unpredictably (utility window screenshot). That image looks fine when drawing one to one (left part of 2_PNG screenshot) but has artifacts when used on 3D objects or used mipmaps (right part of 2_PNG screenshot).


    TGA image has no defects (3_TGA screenshot).


    USAGE:
    1) Open window from Assets menu>Convert PNG to TGA...
    2) Press "Load..." to open PNG image
    3) Toggle "alpha" to show alpha channel
    4) Press "Process..." to convert to RGBA
    5) Press "Save..." to save result as TGA file


    http://u3d.as/content/titov-mykhaylo/png-to-tga-converter/2WR
     

    Attached Files:

    • $02.png
      $02.png
      File size:
      42 KB
      Views:
      5,752
    • $03.png
      $03.png
      File size:
      40.1 KB
      Views:
      5,910
    • $01.png
      $01.png
      File size:
      45.3 KB
      Views:
      6,439
    • $04.png
      $04.png
      File size:
      20.9 KB
      Views:
      5,839
  2. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    This problem is not in TGA vs PSD, and it's not related to compression. The problem is in how PNGs work. Transparent pixel loses its color information, and defaults to "white". If you try to "fix" an existing PNG file, there is no guarantee that it will work by converting it to TGA. None at all.

    What you should do instead is use Flaming Pear Solidify filter in Photoshop (or its Gimp equivalent).
     
  3. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Not really. The format pretty much can deal with colour information in the transparent areas. But some creation steps removes this information then. And some software too. Default white is a typical Photoshop problem for example. An image saved as png by Gimp can have colour informations in the transparent area. At least when you do the right steps.
     
  4. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Most programs have a "Save color of transparent pixels" option when saving to a format that supports transparency. It's important to know what the RGB values are in your image despite transparency, also.
     
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Solidify is a better solution for fidelity: Targa fixes the pixels at mip level 0, but artifacts creep in at other ones. However, Targa/this utility may be faster and more practical, and yield close enough results – much better than PSD.
     
  6. AShim

    AShim

    Joined:
    Sep 24, 2009
    Posts:
    8
    If you prefer to do everything in Unity3D instead of Photoshop the result of this utility looks like Solidify.
    Exapmle:

    sourse + result RGB + result Alpha
     

    Attached Files:

  7. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    What i don`t really understand is why you need to convert from PNG to TGA for that. TGA just makes sense when you have 16 Bit per channel. But the result is still 8 Bit, right?
     
  8. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ah, so you do more than just convert from PNG to TGA. You should have mentioned that in the original post. :)
     
  9. SimonOliver

    SimonOliver

    Joined:
    Jul 16, 2007
    Posts:
    30
    We've been using this and its hugely helpful - removing a number of steps of our export process. Definitely recommended.
     
  10. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    I like!
     
  11. runonthespot

    runonthespot

    Joined:
    Sep 29, 2010
    Posts:
    305
    Yeah, this little utility is great- although one thing, I'd love to see it slightly more tightly integrated into Unity. Currently, when you open the tool, you get a finder window, and have to navigate to the file to convert, and then when you save, similarly have to navigate to a save location. It does exactly what is advertised, and regarding mipmapping, surely converting the TGA into RGBA32 solves that anyway- the point is that it does the whole tedious solidify process in Unity.

    I'd like to see it as a custom asset preprocessor, or at least, a right-click on a file in Unity->PNG to TGA perhaps? Something that enables you to process a batch of files would be great too.

    Mike
    @runothespot