Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Power of 2 texture sizes - Best practice?

Discussion in 'General Graphics' started by dmennenoh, Jan 8, 2019.

  1. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    Curious as to what the best practice is for sizing textures that have the wrong aspect to be power of 2 in both dimensions. Obviously, one side can be a power of 2, but if both are then the aspect ratio will be wrong. Is it best to maintain aspect or best to have power of 2 in both dimensions and scale the object to get proper aspect?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,401
    It depends.

    On mobile and some older desktop GPUs, it only supports power of two textures (sometimes only square power of two textures), so you’re either going to have a texture that’s stretched, or a texture that doesn’t use the whole resolution.

    On modern desktop GPUs this is less of an issue, though most non-compressed image formats are still required to be multiples of some minimum block size (usually 4x4), so some resolutions still might not match up properly. Also, some modern desktop GPUs may allow non power of 2 and even completely arbitrary resolutions for some uncompressed image formats, but on the GPU itself it still allocates the next largest power of 2 dimension’s worth of memory.

    Basically, don’t worry too much about the memory side of things, and just assume you’re going to be using a power of 2 worth of GPU memory regardless of what the inspector tells you.

    Now, if this is a texture that is going to repeat, like a wall or floor texture, I’d always recommended scaling to a power of 2 dimensions. Basically leave Unity’s default behavior for handling these kinds of textures. The whole power of 2 thing is for mip mapping, and it’ll ensure the texture mips and repeats properly.

    If this is a texture for a computer screen, or signage, or a photo, etc. Something that’s not going to repeat, still use a power of two texture if you can most of the time, especially if the slight squish to stretch isn’t too severe or noticeable. If it is a problem, still use a power of 2 texture, but keep the original texture’s pixels and just increase the “canvas size”, filling the empty space with black or some solid color similar to the edges of the image. I use xNormal’s Dilation Photoshop filter for this.

    Basically the only time to use a non-power of two texture is if you don’t use mipmaps.
     
  3. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    Thanks much @bgolus, that's just what I needed.