Search Unity

PVRTC Compression

Discussion in 'iOS and tvOS' started by JoshOClock, May 3, 2011.

  1. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    107
    I'm having some troubles using compressed textures (PVRTC) in Unity on Mac and iOS. It's pretty aggressive which is good for file size but really does some damage to your textures. Especially where transparency is concerned.

    Are other people using it at all or are people using 16-bit or truecolor?

    Anyone know any resources with tips or tricks on building your textures with that compression scheme in mind?
     
  2. ndj23

    ndj23

    Joined:
    Nov 11, 2010
    Posts:
    19
    From what I've experienced, and seen posted quite a bit, only use PVRTC for 3D textures.

    If you're doing 2D of some form (quads with bones, or sprites), then PVRTC really isn't even an option, it destroys the crisp art those types of games require.

    3D games on the other hand(or 2.5D even), compression can be used successfully in some cases, since the level of detail doesn't need to be as high.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Absolutely everything in these screenshots is PVRTC, except the text, and the cube in the last screenshot. It's PVRTC 4 bit for the GUI stuff, and 2 bit for everything else. The textures don't look identical to the originals by any means, but they still work.

    --Eric
     
    Simon-F likes this.
  4. jtbentley

    jtbentley

    Joined:
    Jun 30, 2009
    Posts:
    1,397
    Well that's it, isn't it? It might only be 4 or 2 bits per pixel, but if the resulting texel is in fact smaller than a pixel, that (in a rather gross way) becomes higher.

    If for example, you have a 128x128 at 16bit, or a 1024x1024 (4bit) that's being shown at roughly 128x128, it'll look about on par.

    Ultimately, it's a mobile device, you need to be careful and pick your battles. Some things you just have to take a hit on in terms of memory consumption, others, you don't :)
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not actually scaling anything...the GUI textures are just big enough to work on a retina display, no more. PVRTC is terrible for clean cartoon textures, but something with some noise in it's not that bad, usually. The alpha isn't 100% perfect, but with 4 bit it's close enough for most effects (don't try alpha with 2 bit though). That said, scaling by 4X is a valid technique. 256x256 for 2 bit PVRTC vs 128x128 16 bit is a savings of 2X and it will generally look as good for "noisy" textures. Going up to 1024x1024 is massive overkill in this case. The thing to do is just try PVRTC first and if it doesn't work, don't use it. About 80% of my GUI textures were PVRTC 4 bit, the rest 16 bit RGBA. I didn't need 32 bit for anything, but I didn't use smooth gradients either.

    --Eric
     
  6. Simon-F

    Simon-F

    Joined:
    Jan 17, 2011
    Posts:
    36
    Well, it depends a lot on the texture data. One thing that helps considerably, is not having arbitrary colours in the fully transparent areas. I've seen some example textures where the fully transparent area immediately changes from, say, black to white and the compressor (well, at least the Imagination Technologies' one) will try to faithfully represent that but it means something else will be sacrificed.

    Out of curiosity, whose compressor are you using? Also, do you have an example texture you are trying to compress?
     
  7. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    107
    Here's an image of the results I'm seeing. I'm just using the "Format" drop down in the Inspector and selecting "Compressed". No idea what's happening under the hood.

    So the "1" is the compressed one and the "4" is 16-bit.

    $DogPile4bpp.png

    It's not as visible on a retina display, but not so hot on iPad or Android Tablets.

    It's possible it's the bleed you see in the image on the right, as you're saying, there is some red there and black, maybe it should all just be black.

    The size it compresses it to is pretty stellar though... just not sure what I can do to get a better result.

    And if that is a good result, which considering the size, it probably is, then I'll just be wary about when and how I use it moving forward. Which makes sense, just wanted to be sure there wasn't more I should know about how to use it effectively.
     
    Last edited: May 4, 2011
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use "Advanced" for the texture type instead. But as I mentioned, clean cartoon-style graphics don't work well with PVRTC.

    --Eric
     
  9. JoshOClock

    JoshOClock

    Joined:
    Dec 8, 2010
    Posts:
    107
    Great - that's what was rolling around in my head while looking at this stuff. Just wanted to be sure.

    Thanks for the help.
     
  10. johot

    johot

    Joined:
    Apr 11, 2011
    Posts:
    201
    I have a follow up question here.

    We are currently looking into the final app size vs quality of the textures.

    If a texture is said to be 4.0 mb in Unity will it mean that the final app will be 4 mb bigger? How much can these be compressed when zipped?

    If it's more about the VRAM used then perhaps it's more acceptable to use higher quality textures, but we are more concerned about what it does to our final app size since we would like to get under 20 mb.

    So 4 mb = how much in final app size?
    256 kb = how much in final app size?
     
  11. Simon-F

    Simon-F

    Joined:
    Jan 17, 2011
    Posts:
    36
    Thanks for that. I'll see if I can (despite my lack of artistic talent) draw something similar to add to the test suite for IMG's next generation compression tool.
    PVRTC-1 (which is what is currently exposed by the drivers on PowerVR-based GPUs), sort of assumes non-premultiplied alpha for any completely transparent pixels, and so the likely best approach is to set their colours to something similar to the nearby visible pixels. Again, I don't know whose compressor Unity uses so that might not help.
     
  12. Simon-F

    Simon-F

    Joined:
    Jan 17, 2011
    Posts:
    36
    FWIW, I managed to take the "4" image, and (almost**) removed the sky to produce $FromUnity_dogpile.png
    which it compressed with the "in development" compressor to $DP4-result.png .

    I think it's a little better but, as others have said, I wasn't really targeting cartoon-like graphics when PVRTC was designed. As I said, it may be worth trying to set the transparent areas to a more uniform black.


    ** looks like I didn't do a thorough job on the top and the right-hand side - the remains of the sky are a bit ugly.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    On the device yes, in the store no.

    Depends on how much repeated data there is. Cartoon-like graphics = quite a bit, photo-like graphics = not so much.

    Compress it and find out.

    --Eric
     
  14. johot

    johot

    Joined:
    Apr 11, 2011
    Posts:
    201
    Will do. I'll post my finding here if you want to.
     
  15. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    If you're using it for transparency on a floating object, it generally looks really ratty. However, what I've found it to be great for, is low-contrast grayscale images (paired with low contrast RGB images). You can use the RGB for something else, and colorize the A channel, possibly with vertex colors.
     
  16. johot

    johot

    Joined:
    Apr 11, 2011
    Posts:
    201
    Have anyone here worked with dithering of textures? Any tips on good practices here? Can it be done in Photoshop for example?
     
  17. jimmay

    jimmay

    Joined:
    Sep 23, 2010
    Posts:
    28
    Photoshop supports some dithering if you save for web devices. Actually, for cartoon-like graphics you might be surprised how much you can get out of 8 bit (paletted) graphics with dithering. We're using them for the game I'm working on now and we started out with full 32bit pngs. I tried 16 bit uncompressed pvrs as well as pvrtc 4 bit. I got the same artifacts you're seeing with pvrtc. I was pretty happy with the 16bit pvrs, but I kept looking and found that the 8 bit + dithering looked pretty darn good and was very, very small.

    Honestly, I wouldn't put too much faith into Unity to optimize your textures for you. Spend some time in photoshop, pvrTexTool or texturepacker and you'll be happier. FWIW, I did end up getting almost all the way there using pvrTexToolGui and only running 1 compression pass over the texture. The tool is available at http://www.imgtec.com/ in their SDKs.
     
  18. Simon-F

    Simon-F

    Joined:
    Jan 17, 2011
    Posts:
    36
    As with full-colour PNG, 8-bit palette textures may be small when they are stored inside the application, but they will be expanded to 32-bit textures by the driver prior to being rendered by the GPU. To my knowledge, no GPU has had palette support since the era of, say, Dreamcast or PS2.
     
    Last edited: May 9, 2011
  19. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    correct, there is no 8bit colored format. Already 16bit only exists on mobiles and potentially only for this generation any longer.

    The only 8bit formats supported nowadays are A8 / I8
     
  20. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
    Can you elaborate a bit? What do you gain by using pvrtextool? Can you pre-compress the textures and load them into unity already compressed? Does that override unity's pvr compression? Is the compression pvrtextool does that much better than unity's?