I did a procedural planet generator with quadtrees and correct lod patching but then I decided I want the terrain to be desctructible, and want caves, overhangs and all that cool stuff. So I’m redoing all from scratch using marching cubes.
I have a working implementation of marching cubes capable of rendering a spheric planet with the same noise system I used for my quadtree where the a 2D noise generated the heightmaps.
I’m using perlinNose and rigdegMultiFractal from libnoise, they both have a get method accepting a z coordinate.
What’s not working is the 3D implementation of the noise: if I fill my field with values taken from perlin.getValue(x,y,z) it seems it does not generate a 3d noise, but a stretched 2d noise. I cannot get any overhangs or underground caves, instead my planet looks like a spiked ball: the noise is applied over over again at any distance from the planet to infinite, generating “rays” more than a cloudy mess in 3 dimensions.
So I feel I’m not using 3d noise as I should. I’m not implementing it correctly that for sure, but I ask for help to spot my mistake, or what I did not understand.
To get a planet surface with a decent 3d noise I think that I need a 3d perlin noise to generate me something like this https://i.stack.imgur.com/9WgrV.png and then multiply this with a 2d heightmap noise, more or less.
I attached some images of what it happens:
- the first is when I just perturbate the sphere with the perlin noise.
- the second is when I try to use the noise to generate a messy, dense, 3d field, but instead it doesn’t work and generate infinite spikes
- the third is the same as the second but with some clipping so the planet is still spherized somehow, but still no consistent 3d noise
public void GenerateEmptySurface(float[] field, Vector3 pos) {
int rS = size + 1
for (int x = 0; x < rS; x++) {
for (int y = 0; y < rS; y++) {
for (int z = 0; z < rS; z++) {
Vector3 p = pos + new Vector3(x, y , z);
// distance center - cube chunk position
float d = Mathf.Abs((center - p).magnitude);
//convert to 0-1 range
float t = 1f - 1f/(1f+d);
// get the noise at the 3d coordinate x,y,z, for the current vertex of the current cube
float n = (float)perlinNoise.GetValue((center - p).normalized);
if(2dMode){
// heightmap mode (2d..., like you would in a planet made with quadtrees)
float val = -t * radius + radius;
field[x + y * rS + z * rS * rS] = val +(n/(rS));
}else{
// 3d mode usage test, field is filled when the noise is above some value (and distance less than planet radius just to make it rounded)
if (n < 0f && d<50) {
field[x + y * rS + z * rS * rS] = 1;
} else {
field[x + y * rS + z * rS * rS] = 0;
}
}
}
}
}
}



