Now that I have a operating algorithm for terrain rendering, I wanted to try creating some of it procedurally. This would not be used in order to create levels, but as an alternative to aid artists add some further detail and maybe for some effects. The all-natural planet is extremely noisy and fractal spot, so in order a to get a nice searching atmosphere, these two attributes are vital.
When performing noise for organic phenomena, 1 typically desires some type of coherent noise. Regular white noise, when nearby pixels are not correlated in any way, looks like this:
This is no great when one desires produce terrain and the like. Instead the noise should have a a lot more smooth feel to it. To get attain this, one fades amongst various random values, generating smooth gradients. A way to do this is to create a pseudo-random number (pseudo simply because a certain coordinate, will constantly return the identical random worth) for entire quantity points, and then let the fractional components among these be interpolations. For example, think about the 1D point five.five. To get the worth for this coordinate the pseudo-random values for five and 6 are gotten. Lets say they are ten and 15. These are then interpolated and considering that five.5 lies correct between them, it is provided the value 12.5 ( (ten+15)/2 ). This strategy is actually very comparable to image magnification, exactly where the entire numbers represent the original pixels.
Creating random numbers this way, anything like this is gotten:
This looks okay, but the interpolations are not quite smooth and appears quite ugly. This can be fixed by making use of a greater sort of interpolation. 1 way to to do this is utilizing cosine-interpolation, which smoothen the transition a bit.
This looks a lot much better, but the height map image still appears a bit angular, and not that smooth. However, we can smooth it even additional by employing cubic interpolation. This ties nicely into the image magnification analogy I produced early as cubic is a typical sort of filter for that. It works by not only taking into account the two points to blend in between, but the points subsequent to them as well. In our above example this would be the points four and 7 (which are next to 5 and 6). It appears like this:
This gives a much smoother appearance, but it (as nicely as the other algorithms above) has some other troubles. Since the height values for each and every entire pixel are totally random, it is provides a very chaotic impression. A lot of occasions a single wants a more uniform appear alternatively. To repair this some thing named Perlin noise is utilized. What makes this algorithm additional good is that it based on gradients instead of absolute values for every single pixel. Each and every complete pixel is assumed to have the worth , and then a gradient determines how the worth changes amongst it and a neighboring pixel. This allows it to be considerably far more uniform look:
Due to the fact of it is based on gradients, it also tends to make it attainable to take the derivative of it, which can be utilised to produce regular maps (anything I am not making use of even though). It is also very rapidly, quite a lot identical to the cosine interpolation. The cubic interpolation, which calls for much more random samples, is practically twice as slow.
Now that a coherent noise function is implemented it can be utilised to create some terrain. The screens above does not look that realistic although and to boost the appear some thing known as Fractal Brownian Motion can be employed. This is a really basic approach and works, like all fractals, by iterating an algorithm more than and over. What is iterated is the noise function, starting off with a large distance among the whole pixel inputs (low frequency) and then using smaller and smaller sized distances (greater frequency) for every iteration. The greater the frequency the smaller sized the influence, resulting in the low frequency noise creating the large scale functions and the higher frequency producing the details.
The result of undertaking so can create some thing like this:
All of a sudden we get something that looks a lot a lot more like genuine terrain!
There is lots of stuff that can be done with this and often really straightforward alteration can lead to fascinating benefits. Right here is some iterated fractal noise that as been combined with a sine-function afterwards:
There is a lot much more entertaining stuff that can be accomplished using noise and I have just scratched the surface with this. It is a genuinely versatile technique with tons of usages for graphics. The difficulty is that that it can be very slow though and my implementation will not be utilised for any actual-time effects. Even so, Perlin noise can be simulated on the GPU, permitting it for realtime usage, and this is one thing I might appear into later.
Subsequent up is the hardest component of the terrain rendering - texturing! I am in fact still not sure how to do it, but have tons of tips. Can never ever get sufficient of information though, so if anybody know any good papers on terrain texturing, please share!