title: Texture array in Metal
body: <pre><code>fragment half4 fragmen_shader_test(WaterColorCloudOut params[[stage_in]],
                                                           texture2d&lt;float , access::sample&gt;cloud1 [[texture(0)]],
                                                           texture2d&lt;half, access::sample&gt; cloud2 [[texture(1)]],
                                                           texture2d&lt;half, access::sample&gt; cloud3 [[texture(2)]]
                                                           )
  {
      constexpr sampler defaultSampler;
      float4 color1;
  
      if(params.index == 0){
          color1= float4(cloud1.sample(defaultSampler, float2(params.textureCoordinates)))  * params.color ;
      }
      else if(params.index == 1){
          color1= float4(cloud2.sample(defaultSampler, float2(params.textureCoordinates)))  * params.color ;
      } else{
          color1= float4(cloud3.sample(defaultSampler, float2(params.textureCoordinates)))  * params.color ;
      }
  
   return half4(color1);
  }
  </code></pre>
  
  <p>Here I am using three textures  because of If-else condition the performance drops with time. I feel if i send a texture array to the shader there is no need to perform if else statement. In CPU I have three MTLTexture. How can I bind the three texture to an array and pass it shader.</p>
  
  <p>In CPU side I created three Textures and Created a MTLTexture array</p>
  
  <pre><code> var textureArray:[MTLTexture] = [] 
  </code></pre>
  
  <p>Then I append the Texture to that array.
  In MTLRenderCommandEncoder </p>
  
  <pre><code>let myRange: CountableRange = 0..&lt;2
  commandEncoder.setFragmentTextures(textureArray, range: myRange)
  </code></pre>
  
  <p>In Shader</p>
  
  <pre><code>texture2d_array&lt;float ,  access::sample&gt; texture [[ texture(0) ]]
  </code></pre>
  
  <p>While sampling in Shader</p>
  
  <pre><code>float4 color = texture.sample(defaultSampler, float2(params.textureCoordinates),0) * float4(1,0,0,1.0);
  </code></pre>
  
  <p>I am doing like this currently ButI couldn't get the correct Texture output   </p>