# How to make voxel terrain mesh

I've been trying to make a procedurally generated "pixelated" (semi voxel) terrain (using Unity), as seen in Sebastian Lague's video on simulating ecosystems. (Image attached)

I've tried trawling through the source code, but most of it is over my head. From what I understand, a Mesh is being used to create this, but it has multiple vertices (above each other) where the water intersects the land, which I'm not able to wrap my head around - I'm unable to implement multiple vertices on the same X, Z but different Y coordinates but still connect them with one triangle algorithm. How does one connect these vertices with triangles?

I tried a slightly different approach by simply making Sebastian Lague's procedural terrain generation (from his series on youtube) and rounding the height of each vertex down to the nearest integer multiple of 10, which half worked, but didn't come close to what I was looking for (Image attached of my attempt). I've managed to make stepped terrain, but not the voxel-y one I was going for.

How would I approach making this type of terrain? I've tried summoning a new cube GameObject at each square in a 2D grid, with it's respective height, but this is extremely slow for 100x100 ish grid sizes.

What would be the best way to approach making this terrain?

• Are you looking for code to construct a voxel chunk mesh? Commented Dec 10, 2022 at 12:58
• Yep, this should do the trick, but I'm only going to be generating 3 - 6 layers of height though, and no minecraft-y caves. Is pure voxel terrain still the most efficient way to do this? (I'm going to have a lot of flat plains, so my first approach was to only modify the mesh where the terrain went up or down) I've tried a basic voxel approach and it seems to be working just fine so far.
– Geck
Commented Dec 10, 2022 at 16:39
• If you have a lot of flat planes you could probably improve on this approach in terms of triangle count. The naive version I showed in the link above makes two triangles per voxel face, but you could make larger polygons to span swaths of a plateau all at once. See Texturing different block types on an optimized voxel mesh. If you need help making these solutions work for your use case, can you edit your question to focus on the specific aspect you need help with? Commented Dec 10, 2022 at 19:29
• So if I understand the problem, you have a heightmap (not voxels) and you want to have smooth hills where there are hills, but sharp cliffs where the land touches the water? and currently you are making smooth terrain where the land touches the water? Commented Dec 15, 2022 at 8:58
• @user253751 Hello! Yep, that would do the trick. I've used DMGregory's suggestion of just using a voxel terrain generator, and it worked just fine, but I would definitely like it to only have steep dropoffs where it meets the water (should I post a new question?). I've got voxels and smooth terrain generation down seperately, but I've got no clue how to go about combining them.
– Geck
Commented Dec 15, 2022 at 16:26