Hi, I am testing the new Texture2DArray class, when using the function Apply() it seems to send all the textures to the GPU, even if I didn’t alter most of them, is this the case?If so is there any chance it might change?
I was hoping to use the Texture2DArray in my project to save both GPU processing by using fast indexation in my shader and save on the cost of transfer to the GPU.
Currently, yes. This is very similar to Texture2D.Apply, where whole texture data is sent even if you only changed one pixel. Someday we might optimize this away somehow, but not quite yet.
You could try using Graphics.CopyTexture to copy just one array slice of pixel data, if you already have it in some other texture on the GPU.
Thanks!
That might do the trick i.e sending the a single texture and than copying that texture into a single array element.
@Aras - this means that Graphics.CopyTexture works only with textures that are uploaded to the GPU?
That would explain it - had to go for software atlasing because on build it didn’t work for me, will check if both textures were uploaded at that time and retest.
Would anyone mind sharing or pointing to shader code that uses the new texture2DArray?
Here is some pseudo code straight out of my mind…
In your shader:
Texture2DArray<data type> _textureArray;
Later in your shader you can call any of the Texture2DArray method referenced here:
https://msdn.microsoft.com/en-us/library/windows/desktop/ff471526(v=vs.85).aspx
(note that the compiler is sometimes unfriendly with some of them )
In C#:
Texture2DArray textureArray = new Texture2DArray( sizeX, sizeY, amountOfSlices, textureformat, mipMapsOrNot);
Graphics.CopyTexture( inputTextureObject, inputSliceIndex, inputMipIndex, textureArray, desiredSliceIndex, desiredMipIndex);
yourMaterial.SetTexture("_textureArray", textureArray);
Cheerz!
Sorry for the delay, but here you go, I am using for a terrain, so you can ignore the Vertex shader part of it if you want, you can use the code that Aras mentioned to fill in the Texture2DArray with actual textures.
2638367–185626–ArrayShader.shader (3.5 KB)