Sign in to follow this  
kennyb2142

3D Perlin Noise Map Ridges

Recommended Posts

[code][/code] 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.
[img]http://i130.photobucket.com/albums/p244/kennyb10/ridges.png[/img]

It used to look like this with my old method:
[img]http://a1.sphotos.ak.fbcdn.net/hphotos-ak-ash4/319988_10150854396240237_646780236_20888775_1654179159_n.jpg[/img]

What could I doing wrong? Here's my code for creating cubes:
[code]
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
}
}
}
}
}
}
[/code]

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

Share this post


Link to post
Share on other sites
[quote name='Suspense' timestamp='1318699772' post='4872906']
How did your old method work? What did you change from then to now?
[/quote]

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:
[img]http://i130.photobucket.com/albums/p244/kennyb10/ContinentalProgression1.png[/img]

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

Share this post


Link to post
Share on other sites
Is it something like this you're after?

[img]http://i.imgur.com/zIocp.jpg[/img]

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 this post


Link to post
Share on other sites
[quote name='Calneon' timestamp='1319077366' post='4874528']
Is it something like this you're after?

[img]http://i.imgur.com/zIocp.jpg[/img]

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).
[/quote]

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 this post


Link to post
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 this post


Link to post
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 [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

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

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

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

[CODE]
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.
[/CODE]

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.

[CODE]
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)
[/CODE]

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

[CODE]
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)
[/CODE].

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 this post


Link to post
Share on other sites
I wrote a [url="http://www.gamedev.net/blog/33/entry-2227887-more-on-minecraft-type-world-gen/"]couple[/url] [url="http://www.gamedev.net/blog/33/entry-2249106-more-procedural-voxel-world-generation/"]articles[/url] about this type of thing some time back, that served as the basis for an article in Game Developer magazine. I also [url="http://accidentalnoise.sourceforge.net/minecraftworlds.html"]re-wrote[/url] the thing for my Accidental library, if you are interested.

Share this post


Link to post
Share on other sites
hi,
i don't understand this lines of code:
[quote name='winsrp' timestamp='1340129721' post='4950662']
get perlin 2d for height
for y = 0 to perlin2d
[/quote]

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.
[img]http://www.alrik-online.de/javaw%202012-03-12%2023-20-44-24.jpg[/img]

Share this post


Link to post
Share on other sites
well perlin normally return a number from -1 to 1.. if yours returns from 0 to 1, then maybe some conversions have been applied to it.

something like (0.5 + 0.5 * perlin value.)

and that line means set a variable with the perlin height number

normaly in this step you would also the above transformation and a height amplification

like (0.5 + 0.5 * perlin value.)* max height value.

Then make a look from 0 to the pelin value, assuming that your height array starts at 0. where 0 value = bottom of the world, some number in between lets say 64 = water level and 128 would be something like the highest mountain value. Edited by winsrp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this