Search Unity

NPOT Textures

Discussion in 'Shaders' started by Daniel_Brauer, Jul 20, 2010.

  1. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I hadn't delved into the world of NPOT textures until yesterday, when I found out about how inconsistently they seem to be supported.

    When used on meshes, NPOT textures get converted (not sure exactly when this happens) to ARGB 32 bit textures, and resampled in the process. Strangely, they seem to be resampled using different gamma correction (or perhaps no gamma correction at all) than if you resize them on import.

    When used in GUITextures or in GUI(Layout) functions, they display correctly.

    I assume it's no coincidence that the shaders for these two methods of display aren't accessible. But what are they doing to work properly? Are they atlasing the textures at some point? Is there some under-the-hood switching to the appropriate method of NPOT texture display depending on the hardware?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yes, what happens with NPOT textures at runtime is this:

    * For GUI needs, they are padded with empty space to larger power of two, and GUI stuff is using the correct portion of the source texture. If NPOT texture was compressed, the padded texture stays compressed. GUI is pixel-perfect regarding the source texture.

    * For "regular object needs", they are scaled up to the next power of two. This is to properly support texture coordinate wrapping. If source texture was compressed, this loses compression (the scaled up texture is RGBA 8bit/channel). No gamma correction is done while upscaling.

    So this is not in shaders; just internally NPOT textures get created as two textures. GUI uses one, everything else uses another.
     
  3. Powerstrip

    Powerstrip

    Joined:
    Oct 18, 2012
    Posts:
    1
    Since iOS supports NPOT textures, is there already or can there be, a setting to not pad the textures and use them directly as NPOT? I'm concerned about the additional memory usage from padding. On a 2D game, this can add up to a very large amount. I know using atlases is an option but it's useful to not always need to use them.
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Unfortunately, "support" is a bit more complicated than that. I'm guessing that iOS-specific support for NPOT textures won't come before a more general solution.
     
  5. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
    Hey guys, I'm resurrecting this old thread since it's the first one in Google.

    For a 2D mobile game on iOS and Android, should I always use POT on Sprite (2D and UI)? I'm always using Sprite Sheets so I can easily turn on that option.

    I'm also using pngquant to save spaces. When I look the files, I saved 30 Mo, but the apk generated has only 10 Mo saved. Why ?
    I'm assuming Unity is regenerating the NPOT texture into POT, and so the pngquant optimization applied previously is useless, is that correct?
    Also, I've some texture atlas in 4096 x 4096, on mobile I forced them to be 2048 x 2048 (with the max size option). The pngquant optimizations is also lost here?