Saturday, March 19, 2016

First steps

Creating artificial terrain that looks "pretty good" isn't actually that hard. However, achieving a "realistic" look demands a lot more effort. Today, I'll show you how to do "pretty good"...

Let's say there's a rectangle with height values associated to each of its corners. If we divide this rectangle into 4 identical rectangles, we can see that there are now 5 new vertices (points) for which we could calculate height values.

Now we have to figure out a rule that interpolates (calculates) a new height value from the existing ones.

I decided to go with height variability variable and a constant "roughness" factor that divides height variability at every iteration. New heights are first interpolated for each row, then new rows are interpolated between existing rows.

We could imagine many different ways to interpolate heights but, for the sake of simplicity, ill stick to this one.

All that is left to do is to render the result using a game engine. I used the "Panda3D" engine, which has a Python/C++ API.

Here are three examples using a uniform probability law, for the same random seed, with an initial height variability of 10 and different values of roughness:




Roughness = 1.5 seems to yield the best looking terrain but this method has a problem: the height gradient is too uniform, in other words, you will never find a mountain right next to a valley. To fix this, I introduced more randomness to the height interpolation process. When a new height is interpolated, a mean height value used by probability laws is calculated from the two input heights, which basically means that each height is multiplied by a "weight" of 0,5.

What if that weight was a random number instead?


I was lucky enough to get a nice valley with a tall cliff on the right side, which illustrates my point.

Assigning a random weight was a small manipulation that improved the result, but there is still a lot to do we want our terrain to look believable. We could imagine generating several of such terrain sections with different parameters (to make them look like mountains/hills/plains), then sticking them together. In this case, the heights along the rim of a section would serve as a boundary condition for the adjacent section.

I will leave you with an image of the same terrain with an earth-like color map:


Next time: Planets!

No comments:

Post a Comment