correct implementation of 3d noise (to get a 3d noise volume)

hello!
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;
                        }
               
                    }
               
               }
            }
        }   
    }

I mean if I generate a 2d noise I expect a texture with perlin noise along x and y. if I use 3d noise, sampling along x,y and z should’n t I expect a solid volume with coherent oerlin noise along x,y and z?
Maybe I should sample x and y from u,v position on the sphere and distance from the center as z? but how can this be different from sampling x,y,z from each vertex of the marching cubes? it should still generare a volume but I’m getting always a flat noise.
Either I need a 4D noise (where fourth parameter is distance from center) OR I got the 3D implementation wrong, in the case 3d noise is enough for a 3d cube evenly filled.
I don’t get this, whether or not 3d or 4d maybe?

You’re normalizing the input vector, meaning you’re always sampling the noise from the surface of a unit radius sphere. Just remove the .normalized from the perlinNoise input.

3 Likes

LOL you’re right :smile: Thanks!
2954531--219168--yess.PNG