📜 ⬆️ ⬇️

MineCraft terrain generation

image

Good day to all.
I would like to share my personal experience about the generation of landscapes. It all started with the fact that I played Minecraft and most of all I was struck by the landscape, it was a randomly generated and at the same time beautiful landscape. In general, I confess honestly for a long time that I did not get such aesthetic pleasure when looking at the cuboid-shaped hills going into the distance.

Of course, it became interesting to me, but how does this work at all, on which algorithms and everything like that? Tinkering with the game itself for a long time, as well as having climbed many sites with mods, I didn't learn as much as I would like, but later I found an article in the developers blog about how they used to create their landscape. Naturally, I also decided to try to create my own version of the landscape. Frankly, even after reading this article, I had to search for a long time for other algorithms for generating landscapes, erosion, biomes and smoothing.

And so actually about how I did. At first I tried to do it on the basis of Perlin noise (built a height map and already created a 3D landscape on it), it turned out quite interesting, but as you can see, it’s not very similar to Minecraft.
')
In the 2D version it looked like this.
Simplified code example for Ken Perlin noise.

for x:=-20 to 20 do
for y:=-20 to 20 do begin
n := x + y * 57;
n := (n shl 13) xor n;
ObjectCount:=ObjectCount+1;
Engine.AddProxy(PerlinCube,RootCube,'Cube'+IntToStr(ObjectCount),FileListBox1.FileName,x,2*(1 - ((n * (n * n * 15731 + 789221) + 1376312589) and $7fffffff) / 1073741824),y,0,1,0,1,1,1);
Map2[x,y]:='Cube'+IntToStr(ObjectCount);
end;




In 3d, it looks better, and that is because of the added water level.


After reading the article, I modified it, as it was about before in the game itself. For each block column, the height was (total_ height + (roughness * details)) * 64 + 64. From myself, I added a simple anti-aliasing. It turned out much better.

Here is the simplified part of the code for a small piece:

pod:=4;
nerov:=2;
melk:=1;

for x:=-20 to 20 do
for y:=-20 to 20 do begin
nerov:=Random(3);
melk:=Random(2);
Map1[x,y]:=((pod+(nerov+melk))*5+5)-25;
end;

Engine.AddUCube(RootCube,'PerlinCube',FileListBox1.FileName,x,(1 - ((n * (n * n * 15731 + 789221) + 1376312589) and $7fffffff) / 1073741824),y,0,1,0,1,1,1);

for x:=-20 to 20 do
for y:=-20 to 20 do begin
ObjectCount:=ObjectCount+1;
Engine.AddProxy(PerlinCube,RootCube,'Cube'+IntToStr(ObjectCount),FileListBox1.FileName,x,map1[x,y],y,0,1,0,1,1,1);
Map2[x,y]:='Cube'+IntToStr(ObjectCount);
end;



I filmed in stages.

1. Built a piece of the map.


2. Added Perlin noise.


3. The first smoothing cycle.


4. The second cycle of smoothing.


5. At the end of a few trees that was not so sad.


I am satisfied with the result, although for a full-fledged game like Minecraft, it does not hold out, but for a 2D arcade just right. It was there that I screwed up the generation of the landscape section and threw away the cubes that are above or below the border, which would be more convenient from the point of view of the arcade gameplay.


References
Who cares here is a link to the translation of an article about the landscape of Minecarft.
I really liked the article about Perlin noise link .
Just reminded about a very interesting article on the generation of landscapes link .

Source: https://habr.com/ru/post/128368/


All Articles