Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


3D Perlin Noise Map Ridges


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 kennyb2142   Members   -  Reputation: 107

Like
0Likes
Like

Posted 13 October 2011 - 06:45 PM

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.
Posted Image

It used to look like this with my old method:
Posted Image

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?

Sponsor:

#2 kennyb2142   Members   -  Reputation: 107

Like
0Likes
Like

Posted 14 October 2011 - 08:04 PM

Anyone? I'm still trying to figure this out and I don't think I'm grasping the concept

#3 Suspense   Members   -  Reputation: 449

Like
0Likes
Like

Posted 15 October 2011 - 11:29 AM

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

#4 kennyb2142   Members   -  Reputation: 107

Like
0Likes
Like

Posted 17 October 2011 - 09:15 PM

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:
Posted Image

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

#5 Calneon   Members   -  Reputation: 114

Like
0Likes
Like

Posted 19 October 2011 - 08:22 PM

Is it something like this you're after?

Posted Image

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).

#6 kennyb2142   Members   -  Reputation: 107

Like
0Likes
Like

Posted 06 June 2012 - 08:11 PM

Is it something like this you're after?

Posted Image

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?

#7 jefferytitan   Crossbones+   -  Reputation: 2242

Like
0Likes
Like

Posted 06 June 2012 - 09:09 PM

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.

#8 winsrp   Members   -  Reputation: 273

Like
1Likes
Like

Posted 19 June 2012 - 12:15 PM

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 Posted Image

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, 19 June 2012 - 12:16 PM.


#9 JTippetts   Moderators   -  Reputation: 8647

Like
0Likes
Like

Posted 19 June 2012 - 09:04 PM

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.

#10 Alrik   Members   -  Reputation: 118

Like
0Likes
Like

Posted 21 June 2012 - 05:45 AM

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.
Posted Image

#11 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 21 June 2012 - 11:30 AM

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, 21 June 2012 - 11:33 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS