# Where and how to smooth a voxel-based terrain surface?

I want to smooth the blocky terrain in a Minecraft-like world. The smoothing affects visual appearance and physics but not the logic of placing and picking blocks. I have my mathematical formula to smooth the cubes in a way the voxel grid stays recognizable. But I have no clue how to implement such an effect.

Moreover I do not know how to store and render the effect at all. My smoothing algorithm provides a height for each pixel of a block based on the surrounding blocks. This would result in million of triangles so I might need another approach.

Therefore I thought about calculating the smooth surface dynamically in a shader on the GPU. I never used the geometry shader or the tessellation shader before, but doing so sounds reasonable to me. But with this approach things become difficult when I want to apply correct physics to the smooth terrain surface since the triangles would only be stored on the GPU.

How can I effectively generate a detailed smoothed mesh and access the result for the physics simulation? Is there a technique to implement my idea without the creating of loads of additional triangles?

• "But I have no clue how to implement such an effect." It's going to be hard for someone to suggest how to implement it... if you won't tell us what it is. There are many possible "smoothing" algorithms, and how to implement them depends entirely on what the algorithm is. Commented Mar 4, 2013 at 12:45
• Oh, and if your "smoothing function" is more complicated than a table lookup based on the presence or absence of adjacent blocks, you're doing it wrong. Commented Mar 4, 2013 at 12:47
• @NicolBolas. The smoothing algorithm is a mathematical formula. Given the presence of all adjacent blocks, it calculates the height z for any point x, y inside the block. These coordinates x, y, z are relative to the current block. This calculation is performed for each relative x, y step with given precision and block. every time the world changes. So why do you claim that I am doing anything wrong? I am not doing anything at all yet. I asking for a technique to apply that effect. Something like displacement maps would be great but they wouldn't let physics engine use the results, I guess. Commented Mar 4, 2013 at 13:16

I think a good place to start would be to make things as simple as possible because you stated you don't really know how to implement your algorithm which would make too many triangles anyway. I would like to quickly note that if you smoothed the terrain in the shader it would make huge problems with collision detection and physics since the gpu would be the only thing with access to the smoothed terrain.

The way I propose smoothing the terrain is by using rules to run through when creating the mesh for a block. This is how Castle Story does it and they have a very good blog post on it. Although it focuses on 2d tiles with different textures the bottommost picture translates it to 3d. The simplest way to make "smooth" terrain would be to connect the faces with a diagonal line.

Although I have not actually implemented this (but I will be soon) here is a good forum thread which has pictures of this implemented in games.

This method is a very simple version but it can be expanded using different rules for different sets of blocks... The good part of this method is that it makes the world look decent while still keeping the voxel feel and saving tons of time that would have been invested in a more complex algorithm.

• Alright, I will generate smooth meshes on the CPU whenever a chunk of blocks needs to be updated. Moreover, the linked discussion and the blog post are very helpful. Even though their outcome, to be honest, isn't visually attractive their approach is interesting. I will implement by own smoothing algorithm using bezier curves and hope to show you the results in some months. Commented Apr 11, 2013 at 9:13

I think you are looking for this: Marching cubes

Its an algorithm that forms a (relatively) smooth surface from a voxel field. For implementation I recommend searching with Google as there are lots of articles about it.

It's basically a technique that first determines which neighbors are the same as this voxel, then using a lookup table to determine the mesh for the given voxel in the given situation.

There are multiple implementations, some due to older patent issues(marching tetrahedrons).

You could implement this real-time in a compute shader perhaps, but if your world is static(I mean no more than one chunk is changed at a time), then doing this on the CPU multithreaded is a suitable option too.

• Suggesting to do a Google search is neither helpful nor constructive. Commented Apr 9, 2013 at 13:07
• I am looking for a particular technique to smooth the voxels. Instead I am asking about where to perform the computation, and how to effectively store the result. Commented Apr 9, 2013 at 13:15
• @Bobby I believe that he was merely looking for techniques, there is no way you can google that without knowing the magic words. Showing how to implement marching cubes is not feasible either. Commented Mar 25, 2016 at 20:06