• 11
• 14
• 12
• 10
• 11

# 3D Perlin Noise Map Ridges

This topic is 2132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey so, I've been reading everything I can find on how to use the 3d perlin noise to generate overhangs and ridges but I seem to be not on the right track?
This is what I got using this method:
Add two perlin octaves together. If they are under 0 I turn them into blocks. If they are over 0 I continue and move on to the next one.

Once the sum is under 0, I add the amplitude to them and then proceed. If they are under the water level I draw a lake/ocean over that certain level.. But
It seems I'm missing something, there are lots of random blocks everywhere and only some attached ridges.

It used to look like this with my old method:

What could I doing wrong? Here's my code for creating cubes:
 for (byte chunkX = 0; chunkX < xyChunks; chunkX++) { for (byte chunkY = 0; chunkY < xyChunks; chunkY++) { biomeType = r.Next(0, 5); for (int xAxis = 0 + (16 * (int)chunkX); xAxis < chunkWidth + (16 * (int)chunkX); xAxis++) { for (int yAxis = 0 + (16 * (int)chunkY); yAxis < chunkLength + (16 * (int)chunkY); yAxis++) { for (int zAxis = 0; zAxis < 5; zAxis++) { //15,10 | 30, 8 | 20, 5 <----- Octave 4/5 combos that are good so far //float octave1 = PerlinSimplexNoise.noise((xAxis + worldSeed), (yAxis + worldSeed), 1, 0.0001f); //float octave2 = PerlinSimplexNoise.noise((xAxis + worldSeed), (yAxis + worldSeed), 1, 0.0005f); //float octave3 = PerlinSimplexNoise.noise((xAxis + worldSeed), (yAxis + worldSeed), 1, 0.005f); float octave4 = PerlinSimplexNoise.noise((xAxis + worldSeed), (yAxis + worldSeed), zAxis, 0.009f); float octave5 = PerlinSimplexNoise.noise((xAxis + worldSeed), (yAxis + worldSeed), zAxis, 0.03f); //float cubeGroundBase = octave1 + octave2 + octave3 + octave4 + octave5; float cubeGroundBase = octave4 + octave5; if (cubeGroundBase > 0) continue; octave4 *= 20f; octave5 *= 5f; cubeGroundBase = octave4 + octave5; if (67 + cubeGroundBase < 59) cubeGroundBase = -8; if ((67 + (int)cubeGroundBase) <= 64) //Check if water { int sandLevel = (waterLevel + 3) + (int)cubeGroundBase; //update sand level from base Sand[chunkX, chunkY].Add(new Vector3(xAxis, sandLevel, yAxis)); //Add to water list cubeCollision[chunkX, chunkY][xAxis, yAxis].Add(new BoundingBox(new Vector3(xAxis - .5f, sandLevel - .5f, yAxis - .5f) , new Vector3(xAxis + .5f, sandLevel + .5f, yAxis + .5f))); //add bounding box to list Water[chunkX, chunkY].Add(new Vector3(xAxis, waterLevel, yAxis)); //Also add to list } else //it's grass or dirt { int groundLevel = groundBase + (int)cubeGroundBase; //update ground level with base Grass[chunkX, chunkY].Add(new Vector3(xAxis, groundLevel, yAxis)); //Add grass to list cubeCollision[chunkX, chunkY][xAxis, yAxis].Add(new BoundingBox(new Vector3(xAxis - .5f, groundLevel - .5f, yAxis - .5f) , new Vector3(xAxis + .5f, groundLevel + .5f, yAxis + .5f))); //add cubeboundingbox to list Dirt[chunkX, chunkY].Add(new Vector3(xAxis, groundLevel - 1, yAxis)); //Add grass to list } } } } } } 

I'm only doing 5 for the height? I'm not sure if that's even how you would go about doing this?

##### Share on other sites
Anyone? I'm still trying to figure this out and I don't think I'm grasping the concept

##### Share on other sites
How did your old method work? What did you change from then to now?

##### Share on other sites

How did your old method work? What did you change from then to now?

Hey, thanks for the reply my old method was not using the "density" idea, I just sent the x and y coords into the perlin noise then multiplied them and used the result for the cube height.

Now though I gave up on the density and added an octave using the old method (and modified it a little to give more variation) to produce maps like this:

Although I'm still trying to figure out the whole cliffs and overhangs thing if you could give me some pointers from here?

##### Share on other sites
Is it something like this you're after?

That's done by adding 3d noise to a 2d heightmap. The 3d noise is generated like you would 2d noise, just with a third dimension (im sure you'll find ways to do this).

##### Share on other sites

Is it something like this you're after?

That's done by adding 3d noise to a 2d heightmap. The 3d noise is generated like you would 2d noise, just with a third dimension (im sure you'll find ways to do this).

Yeah that's what I want, but I'm so confused.. What value do I input for the third dimension? And how do I go about looping the perlin values.. like x, y, then z?

##### Share on other sites
I gather that Calneon's approach is to generate a 2D heightmap so that there is a general landscape (no caves etc). After that they generate a 3D Perlin noise field which is only used for subtracting from the existing landscape. So you literally generate a "density change" figure for every x, y, z. If that co-ordinate is already empty, you ignore it (you don't want lumps of rock just hanging in the air). If the co-ordinate contains rock you remove that rock if the Perlin noise at that spot exceeds a certain threshold. You could of course increase or decrease density of the rock as well, to allow a more interesting digging or erosion mechanic.

##### Share on other sites
that kind of landscape is not hard to make, took me a while to figure it out also, worst than a company secrect, no one want to tell

you need to use a 3d perlin function, in combination with a 2d perlin function.

whit 2d perlin you make a height map, just like you are now. So you probably do something like

 for x = 0 to widht for z = 0 to depth get perlin 2d for height for y = 0 to perlin2d make cube 

In order to add the 3d, you need to call one 3d perlin value and use it as density.

 for x = 0 to widht for z = 0 to depth get perlin 2d for height for y = 0 to perlin2d get perlin 3d for density if density > 0 then make cube. 

You would normally also want to use the perlin 3d after you have some ground under you, otherwise you will get empty spaces as in your first screen.

 for x = 0 to widht for z = 0 to depth get perlin 2d for height for y = 0 to perlin2d if y > waterlevel+(some number lets say 8, so you have some nice beach) get perlin 3d for density if density > 0 then make cube. else make cube (density is not important on lower levels) 

Now in order to avoid some of the anoying floating islands you just apply a gradient to the density of the 3d perlin such as

 for x = 0 to widht for z = 0 to depth get perlin 2d for height for y = 0 to perlin2d if y > waterlevel+(some number lets say 8, so you have some nice beach). get perlin 3d for density make gradient (y-waterlevel+somenumber)/(perlin2dheight-waterlevel+somenumber) if (density*(1-gradient)) > 0 then make cube. else make cube (density is not important on lower levels) .

Which this you will have your 3d terrain in no time.

Calneon, how the hell you did the lighting... that thing is killing me.... Edited by winsrp

##### Share on other sites
I wrote a couple articles about this type of thing some time back, that served as the basis for an article in Game Developer magazine. I also re-wrote the thing for my Accidental library, if you are interested.

##### Share on other sites
hi,
i don't understand this lines of code:

get perlin 2d for height
for y = 0 to perlin2d

perlin returns a value between 0 and 1 so how do you implement the for statement?
i also try to create such a world like on the screenshot but it looks strange.