Search Unity

Texture2D has out of range width

Discussion in 'General Graphics' started by mr_madcake, Oct 26, 2017.

  1. mr_madcake

    mr_madcake

    Joined:
    Jul 17, 2017
    Posts:
    94
    Code (CSharp):
    1. RenderTexture.GetTemporary (20000, 1);
    works fine

    Code (CSharp):
    1. Texture2D t = new Texture2D (200, 200);
    works fine

    Code (CSharp):
    1. Texture2D t = new Texture2D (20000, 1);
    Texture has out of range width / height

    I suppose the it should not work this way.
    There is clearly enough memory to store the wide Texture2D (200x200 = 40.000)
    And RenderTexture of the same resolution was created just fine. Am i missing something?

    The most strange thing is that these wide textures were successfully created for a couple of days for me.
    And suddenly i started getting this error.

    Edit:
    After some experimenting i found that the limit is exactly 16384 (power or two)

    Code (CSharp):
    1. t = new Texture2D (16384, 256);
    works
    Code (CSharp):
    1. t = new Texture2D (16385, 1);
    fails

    -------

    version of Unity: 2017.1.1f1
    Windows 7 64 bit
     
    Last edited: Oct 26, 2017
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yeah, today we clamp max Texture2D sizes to 16384. Since that's a common "max supported limit" on many GPUs & graphics APIs. Do you have a GPU that can do larger textures, and are using a graphics API that supports larger?
     
  3. mr_madcake

    mr_madcake

    Joined:
    Jul 17, 2017
    Posts:
    94
    Lol what a coincidence.

    I tried too look up what is the texture size limit in my GPU but without success.

    My specs:
    GT-650m (laptop)
    DirectX 10
    Windows 7 64-bit

    However i did use a texture 19705x1 and it work without any trouble both as Texture2D and RenderTexture.

    I used this texture to calculate vertex positions for skinning and then applied these position in vertex shader. If something was wrong i would immediately notice it visually. Alas with clamping it can no longer work.

    Btw why would you clamp Texture2D but leave RenderTexture as it is?
     
    Last edited: Oct 27, 2017
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    For GT-650M the limit should be 16384.
     
  5. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    As this is graphic card (driver?) specific (and I presume cards may support less than 16384) is there a query for the value through Unity? (something like OpenGL's glGetIntegerv(GL_MAX_TEXTURE_SIZE, ...))

    Madc9ke, can you map pixels to a 2d texture? Fix the width at 256 (that shouldn't waste too much) and do a multiply by 1/256, fract is the x uv and trunc mul 1/the height is the y coord perhaps?
     
  6. mr_madcake

    mr_madcake

    Joined:
    Jul 17, 2017
    Posts:
    94
    Thanks for clarification.
    However it makes me wonder how could my code work in the first place?

    As i said before the 19705x1 texture worked perfectly until the clamping was introduced.
    And wide RenderTextures still work.
     
    Last edited: Oct 28, 2017
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    And this sounds like a bug :)

    Could you please report it?
     
  9. mr_madcake

    mr_madcake

    Joined:
    Jul 17, 2017
    Posts:
    94
    I don't see how this is a bug.
    It's not that Unity allows you to create inherently buggy textures, they actually work as the should.

    If you want an example of code that works with wide textures i have it: https://bitbucket.org/MadC9ke/unity3d-dual-quaternion-skinning/src/?at=wide_texture2D

    I fixed many bugs since that version but it does prove that wide textures actually work.

    So IMHO the bug is forbidding creation of wide/high Texure2D
     
    Last edited: Nov 1, 2017
  10. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    OK, I missed this part :)

    But I would suggest to report a bug with this inconsistensy anyway (Render texture allows this, Texture2D doesn't).
     
  11. mr_madcake

    mr_madcake

    Joined:
    Jul 17, 2017
    Posts:
    94
    Ok, i'll report it with a note that it should probably be allowed for both.
     
  12. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Thanks!
     
  13. Toni333

    Toni333

    Joined:
    Oct 15, 2015
    Posts:
    2
    I have 25600X18000 image here. need to divide it into several tiles??
     
  14. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    Most likely. If you want to support mobile at all, you wouldn't go any larger than 2024x2024. I don't know what a good number would be for most desktop GPUs in this day-and-age, but they all have an upper limit on how big a texture they can handle at once and you probably wouldn't want to limit your game to only player with expensive hardware.
     
  15. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    2048 x 2048

    Yes, absolutely. Even on modern GPUs the largest texture you can really use is 16385x16384. You can split it up manually into smaller tiles, or you can try using something like this:
    https://docs.unity3d.com/Manual/SparseTextures.html

    Alternatively you could use something like Amplify Texture 2 or Granite.
    http://amplify.pt/unity/amplify-texture-2/
    https://graphinesoftware.com/products/granite-for-unity
     
  16. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    Thanks. My math is still asleep, evidently. :)
     
  17. KVinS

    KVinS

    Joined:
    Aug 27, 2013
    Posts:
    21
    I wanted to make a code that cuts textures that are too big, but I can't because they are too big :D
     
  18. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,700
    If you really need that for some reason (using ridiculously large content provided by the user at runtime?) you likely will find some external image processing library which can do that. However a platform-independent solution will be tough.