Question

I've succesfully made a marching cubes class in C# XNA and am using Lib noise to generate 3d perlin noise, but when I tried to generate terrain using the values of the perlin noise as the densities for my marching cubes it generates a large chunk of marching cubes with seemingly random triangles inside of them. I separated the marching cube and gave it arbitrary 3d arrays of densities to run through so I could make sure everything was working and it looked fine, and I had the terrain generation code generate normal cubes and I got a normal looking terrain, but the problem is the corners of each cube gets values from the noise are always switching from negative to positive so fast that the marching cubes just look like a jumbled mess.

This is the code I'm using to generate the terrain:

 public MarchingCube[, ,] getTerrainChunk(int size, int stepsize)
    {
        MarchingCube[, ,] temp = new MarchingCube[size / stepsize, size / stepsize, size / stepsize];
        for (int x = 0; x < size; x += stepsize)
        {
            for (int y = 0; y <size; y += stepsize)
            {
                for (int z = 0; z < size; z += stepsize)
                {
                    Vector3[] corners = { new Vector3(x,y,z), new Vector3(x,y+stepsize,z),new Vector3(x+stepsize,y+stepsize,z),new Vector3(x+stepsize,y,z), new Vector3(x,y,z+stepsize), new Vector3(x,y+stepsize,z+stepsize),
                       new Vector3(x+stepsize,y+stepsize,z+stepsize), new Vector3(x+stepsize,y,z+stepsize)};
                    float[] densities = { GetDensity(corners[0]),GetDensity(corners[1]),GetDensity(corners[2]),GetDensity(corners[3]),GetDensity(corners[4]),
                                            GetDensity(corners[5]),GetDensity(corners[6]),GetDensity(corners[7])};
                    if (x == 0 && y == 0 && z == 0)
                    {
                        temp[x / stepsize, y / stepsize, z / stepsize] = new MarchingCube(densities, corners, device);
                    }
                    else
                        temp[x / stepsize, y / stepsize, z / stepsize] = new MarchingCube(densities, corners);
                }
            }
        }
    return temp;
 }

and the GetDensity method is as follows:

private float GetDensity(Vector3 point) 
{
  return (float)terrain.GetValue(point));
}

I think the problem is that I'm not using the noise correctly to get the densities of the marching cubes corners, but so far my google search results haven't been much help at all. So does anyone know how to use the noise properly to generate smooth looking terrain? Or what else may be causing this problem?

I posted screen shots at http://imgur.com/a/D1uMC , the first two are shown using marching cubes and the last one is normal cubes.

Edit: So from the pictures I figured out that the marching cubes are actually working how they are supposed to with the values they are being given, the problem is defiantly with my noise and how I"m using it. Does anyone know any good resources for 3d terrain generation based on noise?

Was it helpful?

Solution

The problem was how I was reading in the noise, by default I was incredibly "zoomed out" so by changing stepsize to a float and then using smaller increments I was able to get the desired results. Basically "zoomed in" on the area of noise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top