Why are texture manipulation routines so awkward? I’m talking about anything related to get/set/read pixels.
Problems spotted so far:
- Texture2D.ReadPixels read data from globally set RenderTexture.active, meaning we’re technically passing a a function parameter via a global variable, which is not the best practice.
- The rect in ReadPixels is specified using floating point, which makes me wonder what will happen in situation where 1024 is actually 1023.99999999781. Will it round to the nearest integer (sane way), or will it round down and stretch the image (logical way)?
- There’s no Get/SetRawTextureData on Cubemap textures. The only accessible interface is Get/Set pixels. Meaning the data I set will have through the floating point conversion, no matter what I do.
- There’s no GetPixels and no GetRawTextureData on RenderTargets. The only way to grab data is by first transferring it to another texture via ReadPixels.
- There’s no way to set an individual cubemap face as a render target. Apparently they’re supposed to be used with RenderToCubemap only and are not usable in any other way.
- Speaking of which RenderToCubemap does not support replacement shaders and I think it won’t support MRT rendering either.
So, it is awkward all the way around. Apparently to render to an individual cubemap face, I need to:
- Create a temporary render target and render onto THAT.
- Create a temporary texture and read data into it using ReadPixels.
- Get the data using GetPixels (hello, GC allocation)
- And set the data received using SetPixels, for the required cubemap face.
I mean… come on?
The way I see it, the proper way to implement texture objects would be to make sure that they ALL support:
- GetPixels/SetPixels
- GetRawPixelData/SetRawPixelData
And in case of Volumetric textures and Cubemap textures, all those functions would allow user to address individual faces and planes (in volume texture). And of course, it should be possible to set individual faces/planes as render targets.
Can someone, maybe, pass this up to unity devs? ( @Buhlaine or @aliceingameland perhaps?)