Texture2D has out of range width

RenderTexture.GetTemporary (20000, 1);

works fine

Texture2D t = new Texture2D (200, 200);

works fine

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)

t = new Texture2D (16384, 256);

works

t = new Texture2D (16385, 1);

fails


version of Unity: 2017.1.1f1
Windows 7 64 bit

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?

1 Like

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?

For GT-650M the limit should be 16384.

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?

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.

https://docs.unity3d.com/ScriptReference/SystemInfo-maxTextureSize.html

And this sounds like a bug :slight_smile:

Could you please report it?

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

OK, I missed this part :slight_smile:

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

Ok, i’ll report it with a note that it should probably be allowed for both.

Thanks!

I have 25600X18000 image here. need to divide it into several tiles??

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.

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

Thanks. My math is still asleep, evidently. :slight_smile:

I wanted to make a code that cuts textures that are too big, but I can’t because they are too big :smile:

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.