How can I pass an array of textures to a Compute Shader?

In my compute shader, I’ve defined an array of textures:

Texture2D _ColorTextures[22];

In my code, I’ve got an array of 22 RenderTextures (each created by a camera render). How can I pass this array to the compute shader? ComputeShader.SetTexture takes a string (or ID) of a single variable.

One option I’ve seen mentioned is to use a Texture2DArray, but as far as I can tell, in Unity you can’t create a Texture2DArray completely on the GPU, you have to transfer data to CPU and then back, which would be incredibly slow.

Texture2DArray is definitely the way to go. There is content online suggesting it’s possible to render to each slice of the array directly on the GPU, eg https://github.com/catoxliu/RenderT…exture2DArray/Scripts/RenderTexture2DArray.cs

You can write to a RWTexture2DArray on the GPU. See here for a simple example;

Hi, what if I want an array of textures of different size ?

Then Texture array may not be right for you. Either you can use an array but have wasted space on some slices, or consider using an atlas (a single 2D texture with the images laid out on it)