Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

The square texture myth

Discussion in 'iOS and tvOS' started by marsplanet, Jun 2, 2009.

  1. marsplanet

    marsplanet

    Joined:
    Dec 20, 2008
    Posts:
    47
    Just wanted to clear this up. Are there proven benefits of using square textures as opposed to say a 128x256 texture? If I increase the size to 256x256, even though the size is bigger do I get better performance? Does it matter what compression type I use?

    Much appreciated!
     
    liortal likes this.
  2. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Texture which is not square, will not be allowed by iPhone HW to compress it. iPhone do PVRTC texture compression. So, for low memory use, low memory bandwidth and better performance for your game, you should use square texture. You can use other's like PNG ot TGA but they will eat memory and non-square doesn't go through iPhone compression pipe line.
     
  3. marsplanet

    marsplanet

    Joined:
    Dec 20, 2008
    Posts:
    47
    Ah ok. So does it only benefit if using PRVTC, not RGBA 32 bit for example?

    Thanks a lot for the reply!
     
  4. Aaron

    Aaron

    Joined:
    Oct 22, 2008
    Posts:
    122
    care to elaborate on the PNG eating additional memory, from what i could tell PNG would be one of the most efficient image formats. it has low size, and you can limit your colors saving more space if you aren't even using full 256. If im missing something here please fill me in ;)
     
  5. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Image file format is irrelevant as Unity converts all image formats on build anyway. Use PNG, or PSD or TGA... its up to you, for whatever is easiest in your project... they all come out the same on build.

    The only difference sometimes is gamma settings between formats.

    The key here is compressed textures (Square Power of 2) DRAMATICALLY reduce the memory usage for your games... DRAMATICALLY is an understatement.

    Sure, there are times when you want super crisp images for GUI elements and using *some* RGB/A 16 or 24 images are fine, but unless it's 10000% totally imperative to have an image PERFECTLY crisp, use a square texture and set it to PVRTC compression.

    It cannot be stressed enough how important this is. Even if you set a non square or non-power of 2 image to PVRTC, the iPhone or Touch will not treat it as compressed anyway and you will only end up getting crap looking images that are total memory hogs.

    I hope this makes it very clear for everyone.
     
  6. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    To be precise, PVRTC is a 75% reduction in memory consumption. It can also look pretty ugly at times, but you should use square textures whenever possible so the option is always available to you. If your textures are non-square, you're stuck with RGB.
     
  7. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    I wasn't trying to be precise, I was trying to be DRAMATIC! Haha... Thanks :)
     
  8. marsplanet

    marsplanet

    Joined:
    Dec 20, 2008
    Posts:
    47
    Thanks everyone! That makes a lot more sense to me now. Just to clarify, is there any point of making a RGB/RGBA texture larger just to make it square?
     
  9. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    NO. Making it larger just uses more device memory. You want to make them as small as possible, cropped as tight as possible.
     
  10. marsplanet

    marsplanet

    Joined:
    Dec 20, 2008
    Posts:
    47
    Great, thanks a lot for all your help! Really, really appreciate it!
     
  11. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    Well... if you have a 128x256 RGBA, that would be half the size of a 256x256 RGBA. However, a 256x256 with PVRTC is 1/4 that size, and 1/2 the size of the uncompressed 128x256. So adding empty space to a 128x256 texture just for the purpose of compressing it would actually yield a smaller file overall.

    Or to be really specific.
    128x256 RGBA = 64kb
    256x256 RGBA = 128kb
    256x256 4-bit PVRTC = 32kb
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Another thing of importance in relation to the filesize is that it not only saves you texture memory.
    Nearly as important (if not even more important) is the fact that it takes significantly less time to load as the texture does not need to be brought to pure byte data to be uploaded as texture which already takes time, in addition to the considerably smaller memory footprint itself.
     
  13. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    Memory probably being the number 1 killer of iPhone games, I would recommend compressing everything.
     
  14. Choinkees

    Choinkees

    Joined:
    May 11, 2009
    Posts:
    43
    Hmm.. so if I wanted to use a nice detailed graphic to cover the whole screen (e.g. title screen), would it be smarter to use a 512 x 512px graphic rather than a 320x480 ? Still design it as 320x480, but then just add some extra black space or something off the edges to push it out to 512x512 ?
     
  15. drjest

    drjest

    Joined:
    Feb 10, 2009
    Posts:
    44
    As far as I understand it, please correct me if I'm wrong, Unity will take your 480x320 uncompressed 16 or 32bit texture and promote it to 512x512 at load time on the iDevice.
     
  16. joelmgallant

    joelmgallant

    Joined:
    Mar 9, 2009
    Posts:
    113
    If your import settings on the texture are set to scale it up for non-power-of-two textures, yes - it will.
     
  17. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    So looking at texture compression right now...I have a lot of rectangular power of two images...so these are bad and are harming performance?

    I have the import settings as PRVTC, and I have no indication these are set to RGB images. It HAS to be a perfect square just to be certain? Thanks for the help.
     
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Since iPhone OS 2.2 its not required to have square pow2 anymore for compression. Its possible to have rectangular (but still pow2) textures for compression
     
  19. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    Great, thank you.
     
  20. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I never heard anything about this, but that's really important information. Has it circulated around here before?
     
  21. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    yes since Unity iPhone 1.0 or 1.0.1 when ReJ (I think was him at least) mentioned that you just have to replace the pvr compression tool in unity iphone with the one from the sdk

    Its possible that unity does not inform the user of this correctly (at least the gui texture warnings might be missinformative in this case)
     
  22. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Very interesting thread. I'm curious about two alternate techniques then:

    1) In a side-scroller game, is it be more memory efficient to have square mapped elements,(trees, cars, houses, cats, dogs...) and assemble them 3d space for a lengthy lateral game play area. Or use a single long background image if you require, say a city block as opposed to a more abstract pattern? Much like Zombieville.

    2) If the background is looping(again, a city block type, not an abstract pattern), how wide could the image be before taking a serious hit in fps/memory usage? Is a 'wide' background image (multi-screen width) ever a good idea -vs- a multiplane, smaller textures technique?

    thanks,
    B.
     
  23. Deleted User

    Deleted User

    Guest

    What about spashscreen?

    for now i always used 480x320 png.
    Should be better 512x512 to compress splashscreen too?


    Thank you.
     
  24. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    And doesn't aspect ratio come into play? Say if you need a 16:9 texture, use the black padding trick?
     
  25. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Wouldn't compress them.
    They are gone anyway at the main menu so why care about them.

    Also, compressed textures will lose quality which especially for UI and similar things can lead to undesired quality drops
     
  26. ader

    ader

    Joined:
    Jan 27, 2009
    Posts:
    155
    Also, remember the maximum image size, 1024 x 1024 ?
     
  27. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    How exactly does one go about this?
     
  28. MonkeyTrax

    MonkeyTrax

    Joined:
    Mar 31, 2009
    Posts:
    34
    I second this question...How do I replace the pvr compression tool in unity iphone with the one in the SDK?
     
  29. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    This shouldn't be needed anymore with 1.0.2 and higher
    1.0.1 (potentially just 1.0.0) and earlier required it because they happened before iPhone OS 2.2
     
  30. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I've got some textures I want to use for a square part of a GUI, and the size on-screen is going to be 48 x 48 pixels. They don't even look good enough at 16 bit RGBA, so PVRTC is out of the question. Do I gain any benefit from scaling the graphic up to 64 x 64, for it only to be brought back down to size in-game?

    (I don't know if some GPU optimization happens with power-of-two textures, even if they are not compressed.)
     
  31. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    Is this really so? In Unity iPhone 1.5.0f3 at least when having compress when importing on, non-square textures aren't automatically compressed, square ones are. I couldn't find any references other than your quote that textures don't have to be square anymore. As it would be quite useful if the restriction is indeed dropped I'd love to hear more about this! So anyone able to shed some light on this?

    Regards,
    Jaap
     
  32. hrissan

    hrissan

    Joined:
    Mar 9, 2009
    Posts:
    32
    It seems that my 1024x512 textures are not compressed (they eat TONS of memory in Activity Monitor, that's why I have noticed), though they are marked in the editor as having PVRTC format.

    I am using Unity iPhone 1.5.1f2

    Clarification is required. Is there still a code inside Unity which "knows" non-square textures must not be compressed even after the compression tool knows how to handle them?
     
  33. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    As I've found out by now. If you want textures compressed they need to be power 2 and square. If you don't want compression (GUI elements) the texture needs still be power of 2 but not square.

    The square requirement for compression is an iPhone GPU limitation not a unity limitation.
     
  34. Mactivist

    Mactivist

    Joined:
    Jun 25, 2009
    Posts:
    6
    For those of you working on 2D games, something I've noticed while using SpriteManager2 is that it's impossible to get pixel-perfect textures when using an orthographic camera, unless the textures are pow2. They CAN be rectangular, however.

    I also discovered it's pretty easy to lose fps when using large 2D sprites with transparency, such as multi-layer scrolling backgrounds, even if your draw calls and poly counts are low. I'm guessing it's due to hitting the iPhones max fillrate?