2
\$\begingroup\$

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!

\$\endgroup\$
8
  • \$\begingroup\$ Interesting question, also comes with an interesting answer that is basically dependent upon your code design. \$\endgroup\$ – War Aug 17 '14 at 15:13
  • \$\begingroup\$ Lets chat about this: chat.stackexchange.com/rooms/19/game-development \$\endgroup\$ – War Aug 17 '14 at 15:13
  • \$\begingroup\$ Well, I'm missing the reputation for that. \$\endgroup\$ – Minja Aug 17 '14 at 16:30
  • \$\begingroup\$ And what do you mean by based on my code design? I'll just throw some specifics at you: -The world is split into chunks 16 by 128 by 16 voxels -Each chunk has its own mesh, collider and renderer -Currently, every mesh has 1 material attached to it, which contains 3 textures thrown together by the shader \$\endgroup\$ – Minja Aug 17 '14 at 16:33
  • \$\begingroup\$ Unity project by any chance? I've been down this route lol ... essentially what you need to do is use something like a texture atlas and set the uv's on each vert to pull the right texture based on the block type. This doesn't take a lot of code in unity. \$\endgroup\$ – War Aug 17 '14 at 18:30
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ The OP is quite vague this sounds about right to me but he also suggests he's after something Transvoxel below ... im not even sure what he's asking any more. \$\endgroup\$ – War Aug 18 '14 at 21:24
0
\$\begingroup\$

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].

\$\endgroup\$
4
  • \$\begingroup\$ But how would you take different underlying materials into account? Change the texture based on the closest voxel material? \$\endgroup\$ – Minja Aug 18 '14 at 6:39
  • \$\begingroup\$ @user2313940 this wont work ... think minecraft ... triplanar cannot be applied where you have lots of different block types texture atlas is needed. \$\endgroup\$ – War Aug 18 '14 at 14:12
  • \$\begingroup\$ Are you sure that this does not work? I think Eric Lengyel has used this approach in his dissertation (though I don't know how to implement this). It can be found on link \$\endgroup\$ – Minja Aug 18 '14 at 18:28
  • \$\begingroup\$ I see, you're correct if you're using a texture atlas things become a bit more complicated. I use an array of textures myself. this article on voxel, albeit minecraft style, explains texture Arrays in an OpenGL context. link \$\endgroup\$ – Austin Aug 24 '14 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.