I am using instancing to draw a very large amount of cubes in a voxel world (yes another one ... ). So far, all cubes used the same texture, but now i want to use different ones when i build the world.

All my textures are in a unique atlas sent to the GPU i sample from in the pixel shader.

So my question is this, performace wise, what is the best approach to display instanced cubes with different textures ?

With my limited experience, i see only two ways :

1- Instead of calling DrawIndexInstanced once for my 2 million cubes, i call it multiple times for each types of cubes (cubes with different textures).

2- I still call it once, but add a in the instance data the index of the texture in the atas, and to the UV lookup directly in the shader.

3- ?

I am tempted to go with option 2, but i fear doing the texture lookup so often is going to hurt performances real bad in the end.