Implementing multi-texture shading with the marching cube algorithm (voxels)

I am currently developing an asteroid mining/exploration game with fully deformable, smooth voxel terrain using marching cubes. I want to implement an “element ID” system that is kind of similar to Minecraft’s, as in each type of material has a unique integer ID. This is simple enough to generate, but right now I am trying to figure out a way to render it, so that each individual face represents the element its voxel is assigned to. I am currently using a triplanar shader with a texture array, and I have gotten it set up to work with pre-set texture IDs. However, I need to be able to pass in the element IDs into this shader for the entire asteroid, and this is where my limited shader knowledge runs out. So, I have two main questions:

  1. How do I get data from a 3D array in an active script to my shader, or otherwise how can I sample points from this array?

  2. Is there a better/more efficient way to do this? I thought about creating an array with only the surface vertices and their corresponding ID, but then I would have trouble sampling them correctly. I also thought about possibly bundling an extra variable in with the vertices themselves, but I don’t know if this is even possible. I appreciate any ideas, thanks.

You can use a Texture3D instead of a 3D array. You can use material.SetTexture to pass the texture to the shader and tex3D to sample it in the shader.