How to use Texture slices in instanced draw primitive on Apple Metal.

So, I have looking for samples to show how to do that, and I could not find a complete solution, so, it is important to understand the difference between array<Texture, XXX> and texture2d_array

If you understand that, it gets a lot easier immediately. I let you go and read the difference on the apple documentation, but this is pretty clear there.

here is the shader piece you need to understand:

Notice that the index of the texture is passed by the vertexes.

here is the magic for loading the textures with slices …

Objective C loading Texture array with Slices.

Now, you are almost there…  you need to call draw primitive with the right call, including an instance index.

The Draw call … 

Don’t forget to stack one uniform for each of your instance, as the apple sample shows you, and adding this let you change the texture for each object! 

Et Voila 😉