I have implemented the Marching Cubes algorithm to display an isosurface based on voxel data. Currently, it is displayed with triplanar texturing. I'm working with unity, so I have a material with the triplanar shader attached. Now, the whole isosurface is rendered using this material. And thats my problem: I want the texture to represent the voxel data. I'm storing a material value for every point in the grid, and based on this value, I want the texture of the isosurface to change. Sadly, I have no clue how to do this. So if the voxel is sand, I want sand to be displayed; if it's stone, then there should be stone. Right now, everything is displayed as sand. Thanks in advance!
You need to combine texture atlas techniques with your existing triplanar shader so that you can easily switch the "textures" being used based on the terrain type in the voxel.
One technique if you are using shared vertices between voxels might be to use vertex color or UV coords to encode all the terrain types associated with a particular vertex, then you have all the data needed to blend between different terrain textures for a smooth transition between voxels with different terrain types.
If you are not using shared vertices, you can still encode the voxel type in the color or uv data, but you cannot blend textures between voxels.
You could try triplanar mapping. A variation I use is I iterate through vertices and look at the normal of the vertex, find the direction the normal faces most(component of normal vector with the largest absolute value) and use the position components of the vertex vector orthogonal to that direction. and example would be a vertex [1, 2, 3] with a normal [1, 0, 0], the UV vector would then be the y-z components of the vertex, or [2, 3].