# I want to pass the texture array to the fragment shader. But there is a problem

**URL:** <https://forums.kodeco.com/t/i-want-to-pass-the-texture-array-to-the-fragment-shader-but-there-is-a-problem/197532>\
**Category:** Metal by Tutorials\
**Created:** [October 9, 2023, 5:12am UTC](https://forums.kodeco.com/t/i-want-to-pass-the-texture-array-to-the-fragment-shader-but-there-is-a-problem/197532 "2023-10-09T05:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![muzlatte](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/muzlatte/32/105896_2.png) [@muzlatte](https://forums.kodeco.com/u/muzlatte)\
**Post date:** [October 9, 2023, 5:12am UTC](https://forums.kodeco.com/t/i-want-to-pass-the-texture-array-to-the-fragment-shader-but-there-is-a-problem/197532/1 "2023-10-09T05:12:00Z")

</div>

var textures: [MTLTexture?]  
Sent it to the fragment shader with renderEncoder.setFragmentTextures(textures, range: 0…\<textures.count).

Inside the fragment shader, I want to select as many textures as textures.count.  
How do I do it? (However, textures.count is dynamic. [It may be 1 or 5]).

–  
Texture creation options are:  
let textureDesciptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: format, width: width, height: height, mipmapped: false)  
let texture = Renderer.device.makeTexture(descriptor: textureDesciptor)

texture?.replace(region: MTLRegionMake2D(0, 0, width, height), mipmapLevel: 0, withBytes: data, bytesPerRow: width)

–

Thank you.

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [October 9, 2023, 6:04am UTC](https://forums.kodeco.com/t/i-want-to-pass-the-texture-array-to-the-fragment-shader-but-there-is-a-problem/197532/2 "2023-10-09T06:04:43Z")

</div>

You can’t use dynamic arrays in shaders.

If you need a dynamic number, you can send the actual number in something like Params.

The dynamic number of lights in an array is an example.

However, you can use a texture array. This stackoverflow answer may help you: [ios - Texture array in Metal - Stack Overflow](https://stackoverflow.com/a/54240792)

---

<div class="post-metadata">

**Author:** ![muzlatte](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/muzlatte/32/105896_2.png) [@muzlatte](https://forums.kodeco.com/u/muzlatte)\
**Post date:** [October 13, 2023, 3:08am UTC](https://forums.kodeco.com/t/i-want-to-pass-the-texture-array-to-the-fragment-shader-but-there-is-a-problem/197532/3 "2023-10-13T03:08:09Z")

</div>

Thank you  
I found another way to solve it. 😃
