How can a voxel terrain (marching cubes) be textured without triplanar mapping ?

The goal being to have more artistic freedom.

I think, I could unwrap the mesh while extracting the isosurface then use projective painting. But I do not know how to handle terrain modifications without breaking the texture. I also guess that virtual texturing could help here.

Links for these matters would be appreciated.

  • \$\begingroup\$ Marching Cube terrains don't require triplanar mapping, but there are stretching artifacts if you use a single planar texture mapping. Are you trying to paint the mesh like an unwrapped model typically is? \$\endgroup\$ Jun 20, 2013 at 10:48
  • \$\begingroup\$ I think painting the mesh is the solution, but the geometry being regenerated each time you modify voxels the texture will not match the model any more. \$\endgroup\$
    – Thelvyn
    Jun 20, 2013 at 11:29
  • \$\begingroup\$ You could paint each different marching cube variation and offset the UV's to select different parts of the texture based on world coordinates. \$\endgroup\$ Jun 20, 2013 at 19:24
  • \$\begingroup\$ My idea is indeed to get each chunk (let's say octree leaf node), unwrap it, build a basic texture, then paint it. But each modification of the chunk will reset the texture. The question is: is there a way to avoid this reset ? I guess there is not, that's why I asked (I do not like to assume things without confirmation). \$\endgroup\$
    – Thelvyn
    Jun 21, 2013 at 8:11
  • \$\begingroup\$ There are a set number of marching cube cases where UV coordinates could be generated correctly for each case. This would fix your chunk reset issue. This relies heavily on texture reuse though, so if you're trying to have unique texturing throughout, it would be a problem. \$\endgroup\$ Jun 21, 2013 at 17:56

2 Answers 2


Faking it

"I do not know how to handle terrain modifications without breaking the texture."

This is the crux of the matter, because you'll have lost the original source of information -- the conceptual material volumes painted on by your paintbrush -- as soon as you transfer it onto the 2D texture. So you'll have no volumetric reference from which to reconstruct your 2D texture UVs. This is where 3D textures become far more useful. But you don't need 3D textures as such, if you're willing to opt for a simpler painting process... just a 3D dimensional backing array that you'd use as a reference for where you've painted and where you haven't i.e. where certain materials lie beneath the terrain manifold. Unless you plan to use octrees or have a fairly tiny world, you'll probably want to make your "backing" data structure used for retexturing, quite low-resolution (relatively large cells).

Perform the paint operation in 3D space, with resolution equal to that of your quantised / voxelised "backing" 3D array. The paintbrush (also quantised / voxelised) will need to snap to these backing cells as you move it through space, in order for it to paint the backing array accurately. Your paintbrush might be of uniform colour, or every voxel (as opposed to texel) might be a different colour.

When time comes to (re-)construct, project from the each vertex, outward along the appropriate world axes, until you hit the implicit "face" of the backing cell into which this vertex falls. By sampling that point within the plane, you can get the UV for your terrain vertex (may require some averaging if you need to sample on multiple axes). I guess you'll also need to handle transitions somehow, i.e. where one triangle lies in one backing array cell, and the other two lie in (a) different cell(s). As these are rectilinear raycasts, and you will only be doing them in the locale of terrain changes, the cost over time will be negligible (and the majority of your level terrain will undergo this sampling as a pre-process before play begins).

(I'd suggest keeping your subject mesh simple to start with, as it may make things easier to conceptualise.)

The Real Deal

Alternatively, make use of 3D textures. You don't talk much about your intended paintbrush, so I cannot tell if you intend to use a 2D texture, 3D texture, or plain / uniform colour, for painting your terrain. Irrespective, this approach will work for all of the above.


Similarly to @ArcaneEngineer, I think the way to go is to store material information (in your case just a texture id) with each voxel. Like in Minecraft, you'd have voxels of different kinds of materials. However, you'll have a much higher resolution since you're smoothing this terrain representation using Marching cubes. When adding voxels to the terrain, you can copy the material of the ground they get appended to and use that in the new voxels as well.

Now, the thing is that you can't unwrap your whole terrain geometry to a 2d texture evenly. However, if you don't plan to blend materials, it is easy to texture your smoothed terrain without stretching artifacts.

First, you have tiling 2d textures for each kind of material. With your marching cubes look-up table, you also store texture coordinates that nicely unwrap that corresponding geometry patch. Then, you have vertex buffers for each bunch of areas in your terrain that share the same material. You can now render those buffers with the same static texture of their material. There is no need to generate a new texture every time.

When you want texture blending, things get more complicated. In that case, I think you need to dynamically generate the texture of your terrain. You can consider procedural texturing for marching cubes for this.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .