Search Unity

Are texture dimensions resized to powers of two?

Discussion in 'Scripting' started by HonoraryBob, Sep 16, 2012.

  1. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    Does Unity automatically resize runtime-generated textures so that the dimensions are powers of two?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No.

    --Eric
     
  3. iaanus

    iaanus

    Joined:
    Nov 15, 2012
    Posts:
    13
    Actually, yes. I wrote in C# the following:

    Texture2D texture = new Texture2D(152, 30);

    while Unity claims that texture.width == 152 and texture.height == 30, the allocated texture produces clearly visible artifacts as if it were bigger than that. I then wrote a native plugin and inspected the texture pointer retrieved with GetNativeTexturePtr() and I can confirm that the actual texture size is indeed 256x32. As a further confirmation, I applied a mainTextureScale equal to (152/256, 30/32) and the artifacts disappeared.

    IMHO, this is a bug in Unity. You should either get what you asked for (a 152x30 texture) or (if that's not possible/feasible/desirable) texture.width and texture.height should return the actual size of the allocated texture. Having texture.width and texture.height return the wrong value is totally useless and a possible source of bugs.

    - Alberto
     
  4. iaanus

    iaanus

    Joined:
    Nov 15, 2012
    Posts:
    13
    This bug appears to be fixed in Unity 4.1. Very good.
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I see.. I rely on this as well and will need to actually change some sloppy code from using width height to constants then when we find valid reason to actually move to 4 :)