[26/03/11] : V. 0.01
Small update; Faster, removed the yields in the script as well, although it stops unity while the script is thinking. For a terrain using default settings (calculating 131,072 points), it should be created in under 2 minutes; still very slow, between 1000 & 1200 points per second.
I found some extra time these past couple of days, and decided I'd play with Unity for a bit. I figured that I'd come up with a procedural terrain system allowing overhangs, tunnels, etc.
I started last night, and got some of it working this morning. I began by looking up perlin noise, and making my own implementation of 3d perlin noise (or something similar) using the now-accessible multi-dimensional builtin arrays.
I have it working, but it is incredibly slow, as it always seems to be with codes in the first little while after writing them. Also, I'm making the terrain out of cubes, which means that it resembles minecraft a lot (hopefully I can change this by using something similar to marching cubes, and then smoothing).
It does work very similarly to minecraft, in that they both use 3d perlin noise. I also decided to generate terrain in blocks, because it seems to be the only feasible method to generate terrain in real time and save it (I'm still not there yet).
Well, I'm posting it in this early stage because I figure it could be a useful start for others who might know a lot more about this type of thing than me. I'm also not sure how much time I'll have in the next little while to improve it.
More notes can be found in the script itself.
Some blocky terrain generated by the script (cubes are prefabs)
Overdraw view of perlin noise (not terrain, see notes in script)
Terrain Blocks : The amount of blocks in the x & y directions the script creates. (4 would be a 4x4 grid of terrain blocks)
Cube : A cube prefab goes here.
Detail Size : The distance between integral areas, or at least that's how I like to describe it. Basically, the size of the noise. (since it's not limited to a terrain size)
Persistence : How noisy the terrain will be. (persistence in Perlin noise)
Octaves :Amount of iterations it goes through, in which size and persistence change each iteration. (octaves in Perlin noise)
Terrain Size : The length and width of a terrain block; the total size of the terrain is (Terrain Size)^2*(Terrain Blocks)^2.
Terrain Height : The maximum height of the terrain (average height is half of this)
Seeded : The random terrain seed. The same seed will always generate the same terrain.
My first though when i opened this thread was: Minecraft
If you want your noise function be quicker google little about perlin noise.. There are newer implementations that were developed by Perlin himself that solve some problems with speed. Can't remember how it's named but utilizes different approach in computation and it's faster and more lightweight.
| www.quickfingers.net || Follow me on Twitter |
Step-seq : A music creation toy based on ease of use and ear pleasing results!
Stratosfear : A 7 Day Game Prototype Challenge based on themes "Rising" & "Companion"
Surrender : Epic Sci-fi desert warfare
SRL : My 7 day roguelike game on board an alien infested cargo space ship
There are some common misconceptions about Perlin noise:
Perlin noise, does not have octaves. It gives you just one single octave.
A very common use of Perlin noise is to sample perlin noise at multiple frequencies (octaves), and add the results together at different scales. This is called fbm or Fractional Brownian motion. When you do this, instead giant smooth hills, you get giant hills with smaller features. This is a very common way to create realistic heightmaps.
Perlin noise is a gradient based noise. What you are doing is called a value based noise, which has nothing to do with Perlin. The difference is: gradient noises calculate a gradient at each discrete point, values at the discrete points are always 0, and values between discrete points are obtained by projecting the gradients. On value noises, you calculate a value at each discrete point and interpolate the values for points between them.
What you have implemented is a fbm of value based noises. Very similar to what is described here:
The author of that has the exact same confusion. He calls his fbm of value based noises "Perlin noise", so my guess is that is what you based your code on.
If you are after speed, I recommend you implement simplex noise, as described here:
That article also has a good explanation of what perlin noise really is.
It is much harder to understand, but it just works faster and has higher quality. Also, allows you to calculate the derivative, which means that in your heightmap, you can calculate whether you are on a slope or not and how steep it is. You can then create an fbm (multiple octaves) based on simplex noise for interesting heightmaps, or even caves.
If you wish to get some numbers: I calculate 7 million blocks calling 3d simplex noise 3 times and 2d simplex noise 4 times in 4.2 seconds . In order to create this:
This video is outdated, as my terrain is much better nowadays, but it gives you an idea.
Another good article that hopefully clarifies things is:
Page 16 shows you a simple value noise
Page 17 shows you an interpolated value noise. This is essentially what you have in your function "InterpolatedNoise"
Page 23 shows a gradient noise
Page 24 and 25 shows a gradient noise with interpolation
Page 36 shows simplex noise
Page 42 shows fBM. This is equivalent to what you implemented.
Here is an implementation of simplex noise with derivative, that you can easily translate to C#:
I like the article you posted.. I will look at it further a bit later but I like the cave generating method. Can't believe that I haven't came up with it sooner . I will try to rewrite your code so it doesn't instantiate cubes but that it makes the mesh procedurally instead if I have time...I so hate time .
Glad it gave you some insight. It is not my post, I just happened to stumble upon it a while back and bookmarked itI like the article you posted.. I will look at it further a bit later but I like the cave generating method. Can't believe that I haven't came up with it sooner . I will try to rewrite your code so it doesn't instantiate cubes but that it makes the mesh procedurally instead if I have time...I so hate time .
Thank you for this. No, I had not read it, I wish I knew about that post 6 months ago
There is always this gem as well.
Fast, works well, and easy.
i am wondering is it still alive cause none posted in long time and
also what about Procedural part of process? is it possible to make it?
No Image BBCode - NO SIGNATURE FOR YOU
Sorry for bringing this back up after three weeks, But I was wondering if I could get some tips or suggestions on having this generate in a hollow manner.
As in only the sides and the top of the terrain are created and none of the cubes on the inside are instantiated.