Mucking about with Marching Cubes

I saw this video on doing marching cubes in Unity, marching cubes is one of the algorithms that can be used to generate a 3d polygon surface from a voxel type density field it was developed for things like cat scans or mri it's also probably the algorithm things like Astroneer use to have deformable landscapes.

There are newer possibly better algorithms for doing the same thing but marching cubes is the simplest. I've wanted to try it out for a while but have never gotten round to working out how to implement it. The basic idea is based on a set density you define as "solid" you test the 8 corners of a cube to see if those points are solid or not then there are a set of 16 different mesh types you can generate based on that.

Today I saw a youtube video by Sebastiian Lague in his unity based coding adventures series ( see here on how to implement the algorithm in unity using lots of clever stuff.
I thought I'd have a go at doing it using Godot and over my lunch break I knocked a quick prototype together

Works fairly well if a little hardcoded and just makes a voxel space some 20x20x20 the a quick bit of opensimplex noise to give the density and away it goes. Some odd things like the collision generations seems to have a gap there you can slip through but not bad for a first bash.

I might well play with it some more make the terrain deformable or some such


did a quick and dirty deformation addition based on spheres sets either inside or outside sphere based on mouse input

Very very quick and dirty, would be better if I increased and decreased existing density values in the area selected rather than punch out a sphere where the raycast hits

Evilmatt's picture

Added a simple deformation option that adds or subtracts from or to the existing density. My astroneer clone is almost done :D

One of the faults seems to be if you update the landscape under the "player" you can end up falling through the terrain as it updates its collision mesh

Evilmatt's picture

That is super sexy, EMW. Love it.

brainwipe's picture

Added some simple triplanar texturing using godot's visual shader system

just uses the godot logo as a test texture

Heres a shot of the fragment shader it just blends each of the planes (xy,yz,xz) depending on the surface normal.

Evilmatt's picture