Terrain

View previous topic View next topic Go down

Terrain

Post by SpiderPork on Mon May 23, 2011 10:25 am

Hey!
I must say I'm quite impressed with the progress you have so far, but there's one thing I want to know.
How do you generate all that awesome terrain? Noise most probably, but how do you create all those awesome mountains, valleys and things?

Thanks.

SpiderPork

Posts : 7
Join date : 2011-05-23

View user profile

Back to top Go down

Re: Terrain

Post by Slaihne on Mon May 23, 2011 11:13 am

I start with a smoothed noise which gives me a value between 0 and 1.

So, as my X, Z coords vary within the world the noise value is smoothly moving between 0 and 1. Then if i want something like a plateau i check if the value is, say, greater than 0.75, and i make it 0.75.

So now that noise varies smoothly between 0 and 0.75, with largish expanses of flat areas at 0.75.

I also do things like divide my noise value by 100 and add it to the overall noise and i now get a little bit of 'roughness'.

What i found helps is to write a little program that shows what you're gonna end up with as a grey scale (or colours for more complex functions). Then you can tinker round with individual things that you can then add up to get the final product.

I use functions to get the following values for each column of blocks...

A rolling value (flatish slow slopes)
A mountain value (spikey mountains)
A 'Swing' value to switch between them (slowly)

That gives me the overall feel of the terrain.

Then, i have an earth thickness value to allow bare rock in certain areas.
A plate techtonic value to give cliffs, it's sort of like a sawtooth.
2 cave levels, one below sea floor level and one around sea level, these cut into the ground already created.
Seas and rivers are made with a couple of functions merged. These cut into the landscape again.
A shard value for the big pointy things.

I generate the block column with several layers of rock blocks, offset with the overall terrain. Then i cut into the column to gives caves / rivers etc.

If you google something like "perlin noise terrain" you will find loads of articles.

I found it's mostly a matter of thinking about it and what you want to achieve. The little program i mentioned really helps too.
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 49

View user profile

Back to top Go down

Re: Terrain

Post by S33m3 on Mon May 23, 2011 1:53 pm

I would add that you have 2 paths you can follow (or mix) to create your terrain.

First path, the 2D path :
From Slaihne description, he seems to mix 2D noises values.
Simplified by : NoiseFonction(X, Z) = Height value at this point (Or Y).

The advantage is that 2D noises are really fast to compute even at high octaves. The disavantage, is that it's difficulte to generate "3D" terrains without mixing a lot if 2D noises.

For my terrain I follow the other way : "3d" path.
My main noise fonction is a 3D noise.
Simplified : NoiseFonction(X, Z, Y) = "Density" of the rock at this 3d point.
If densitY > X then Rock else "Air".

The advantage is that it give directly "true" 3d terrain, with simple to none modification needed to it. The disavantage is that it needs a LOT more Noise fonctions to be computed for the terrain generation.
For my engine, I use a mix of 3d and 2d noises. To handle the slowness of the generation I interpolate the 3d results.
By interpolation I mean that instead of starting the noisefonction(X, Z, Y) for each block, I do it only every 4 blocks, and simply compute the interpolations for the blocks not directly computed for the noise. It gives really nice results nearly impossible to have using only 2D noises.


S33m3

Posts : 54
Join date : 2011-03-23

View user profile

Back to top Go down

Re: Terrain

Post by SpiderPork on Wed May 25, 2011 9:11 am

Thanks for your replies. One more thing I want to know: How do you store the blocks since there's almost no lag?

SpiderPork

Posts : 7
Join date : 2011-05-23

View user profile

Back to top Go down

Re: Terrain

Post by Slaihne on Wed May 25, 2011 9:27 am

I'm not quite sure what you mean here.

I store the blocks in a huge (wraparound) array. I generate them as you move towards the horizon. All i need to be able to do is generate a line of chunks (16x128x16 blocks) before the next line comes over the horizon. If you could move fast enough then you would 'beat' the generation of the terrain and end up floating in nothing-ness Smile
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 49

View user profile

Back to top Go down

Re: Terrain

Post by SpiderPork on Thu May 26, 2011 5:41 am

Yea, I wanted to know that, thanks. Very Happy

SpiderPork

Posts : 7
Join date : 2011-05-23

View user profile

Back to top Go down

Re: Terrain

Post by SpiderPork on Sat May 28, 2011 11:45 am

Sorry to bother you again, but...
... would you mind giving out some noise values you use in your noise function? I just really want to test out your terrain on my engine Very Happy

SpiderPork

Posts : 7
Join date : 2011-05-23

View user profile

Back to top Go down

Re: Terrain

Post by S33m3 on Sat May 28, 2011 1:45 pm

You should really try it be yourself.
It's not that complicated to have something out from noise fct., but much more to have something that looks nice.

That's the "magic" behind thoses noises fonctions values, and I would understand Slaihne not giving up exactly the values used to generated its landscape.

S33m3

Posts : 54
Join date : 2011-03-23

View user profile

Back to top Go down

Re: Terrain

Post by SpiderPork on Sat May 28, 2011 11:17 pm

I understand what you mean. I mix 3 noise values in my function, but I either get a very mountainous or a flat world. I can't get the two combined.

SpiderPork

Posts : 7
Join date : 2011-05-23

View user profile

Back to top Go down

Re: Terrain

Post by S33m3 on Sun May 29, 2011 12:19 am

You have to understand what's the impact on every variables used in the noise fct. Here is small explanation, you can find better article on the net.

Code:

        X = X location.
        Z = Z location
        octaves = The number of octave to use for the noise
        persistence = The impact of each octave to the noise result (1 = as important as the previous one)
        _zoom = similar to the computed frequence, but constant over each octaves

        private double SimpleNoise2DValue(double X, double Z, int octaves, double persistence, double _zoom)
        {
            double NoiseValue = 0.0;
            double frequence;
            double amplitude;

            for (int i = 0; i < octaves; i++)
            {
                frequence = System.Math.Pow(2, i);  // Frequence high = Montainous               
                amplitude = System.Math.Pow(persistence, i); // Give more amplitude to an octave

                NoiseValue += noise(X * frequence * _zoom,  Z * frequence * _zoom) * amplitude;
            }
}

As you can see here you have already seeral possibility to mix the Octaves.
In my exemple the actoves results are added (+=)
But you can also do :
value += Math.Abs(noise(X * frequence * _zoom, Z * frequence * _zoom) * amplitude;
or
value += (1 - Math.Abs(noise(X * frequence * _zoom, Z * frequence * _zoom))) * amplitude;
Try them to see the difference.

Then After you have to possibility to combine the result of various noise result !

Value for a point :

double value = SimpleNoise2DValue(1000,6450, 5, 0.75, 100);
double Threeshold = SimpleNoise2DValue(1000,6450, 1, 0.50, 50);
if(Threeshold < 0.5)
value += SimpleNoise2DValue(1000 / 2,6450 / 2, 2, 0.20, 100);
else
value -= SimpleNoise2DValue(1000,6450, 5, 1, 10);

(It's just an example, don't know if it will render something "nice" or not).

Regards.

S33m3

Posts : 54
Join date : 2011-03-23

View user profile

Back to top Go down

Re: Terrain

Post by SpiderPork on Sun May 29, 2011 1:06 am

Thanks a lot for this. I'll dig into it and try something soon Smile

SpiderPork

Posts : 7
Join date : 2011-05-23

View user profile

Back to top Go down

Re: Terrain

Post by SpiderPork on Sun May 29, 2011 11:21 am

It's quite impressive there is almost zero lag. How do you accomplish this?
(Really the last thing I want to know - sorry, but I'm curious Razz)

SpiderPork

Posts : 7
Join date : 2011-05-23

View user profile

Back to top Go down

Re: Terrain

Post by S33m3 on Sun May 29, 2011 11:54 am

Multithreading

S33m3

Posts : 54
Join date : 2011-03-23

View user profile

Back to top Go down

Re: Terrain

Post by Slaihne on Mon May 30, 2011 3:01 am

Hi SpiderPork,

S33m3 seems to be giving you some sound advice.

The only thing i could really add would be that you should get one generator to give you something like rolling plains. Then get another to give you jagged mountains. Then use a third generator to switch between the two smoothly. This third one would be something like your rolling plains but when it hits 1 the end result would be all the jagged mountains and none of the rolling plains. When it hits 0 the end result would contain none of the jagged mountains. This means the landscape would smoothly transition between plains and mountains.

If you set up multiple generators for multiple landscape types you can use the "switcher" to move between each type.

And as S33m3 mentions, the key to reducing lag is doing this in another thread.
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 49

View user profile

Back to top Go down

Re: Terrain

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum