MineCraft landscape generation

image

Good day to all.
I would like to share my personal experience with landscape generation. It all started when I played Minecraft and the landscape hit me the most, it was randomly generated and at the same time beautiful landscape. In general, I admit honestly for a long time I did not get such aesthetic pleasure looking at the cube-shaped hills that go into the distance.

Of course, it became interesting to me, but how does this even work, on which algorithms and all that. Poking around with the game for a long time, as well as climbing many website with mods, I didn’t learn as much as I would like, but later I found an article on 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 that article I had to search for other algorithms for landscape generation, erosion, biomes and smoothing for a long time.

And so actually about how I did. At first I tried to make based on Perlin noise (I built a height map and created a 3D landscape from it), it turned out quite interesting, but it’s not very similar to Minecraft.

In the 2d version, it looked like this.
A simplified code example for Ken Perlin noise. In 3D it looks better, and even then because of the added water level. After reading the article, I modified it, as it was approximately earlier in the game itself. For each column of blocks, the height was (total_height + (roughness * details)) * 64 + 64. From myself, I added a simple smoothing. It turned out much better. Here is the simplified part of the code for a small piece: I photographed in stages. 1. A slice of the map is built. 2. Added Perlin noise. 3. The first smoothing cycle. 4. The second smoothing cycle. 5. At the end there are few trees that were not so dull.

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;











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 am satisfied with the result, though for a full-fledged game like Minecraft it does not hold out, but for 2D arcade games just right. It was there that I screwed up the generation of a section of the landscape and discarded cubes that were 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 a translation of an article on the Minecarft landscape.
Loved the article on Perlin noise link .
They also reminded about a very interesting article on the generation of landscapes link .

Also popular now: