- Home /
How to use texture array in shader?
I use array parameters in shader for better performance. For example, I declare parameters in shader:
sampler2d textures[2];
float4x4 matrics[2];
float4 transforms[2];
and set these parameters by this way:
Shader.SetGlobalTexture("textures0", xxx);
Shader.SetGlobalTexture("textures1", xxx);
Shader.SetGlobalMatrix("matrics0", xxx);
Shader.SetGlobalMatrix("matrics1", xxx);
Shader.SetGlobalVector("transforms0", xxx);
Shader.SetGlobalVector("transform1", xxx);
for float4x4 and float4, they are both work fine. However, when I use texture array in shader, there is a compile error:
"sampler array index must be a literal expression"
How to deal with that?
Answer by petersvp · Mar 08, 2016 at 04:04 PM
Unity 5.4 will have the Hardware Texture array support.
I am having the same problem passing texture array into shader, which method should I use?
https://gist.github.com/Spaxe/57de76c993a4dc8bb37275acbe597ef2 I used the code there, and it worked, the c# code will add an item in menu: GameObject->Create Texture Array
Your answer
Follow this Question
Related Questions
Texture2D Array Appears Grainy 0 Answers
Uploaded sprite can't set bones and poses 1 Answer
Using Array of Structs in Shader 1 Answer
Why is Unity generating grayscale normal maps? 0 Answers
How to use array in cg shader 1 Answer