what technics and math involved in making randomly generated worlds in video games? like space engine for example?

572 views

what technics and math involved in making randomly generated worlds in video games? like space engine for example?

In: Mathematics

3 Answers

Anonymous 0 Comments

Generally the base of a procedurally generated world is generally something called Perlin noise. It creates something that looks like [this](https://rmarcus.info/blog/assets/perlin/raw_perlin.png) a continuous black and white image where you can have the black bits represent low elevations and white bits high elevations. In space engine I imagine the perlin noise is wrapped around a sphere, or they just use a perlin noise generator that uses spherical coordinates in the first place.

I’m far more familiar with Minecraft world generation I will use that instead but similar ideas should arise in other games, perlin noise is nearly ubiquitous in procedural worldgen. At this point in the Minecraft world generation, you have a stone world filled with valleys mountains and planes. For any z coordinate less than 60 ish, Minecraft replaces any air blocks with water at this point.

As it starts, it’s a stone world. At this point biomes are made by using more perlin noise, the game creates another two perlin noise maps known as temperature and rainfall and based on this chooses the biome for a certain location (dry warm biomes are deserts for instance, etc, even if the game has no real notion of temperature).

Biomes might do some things, such as in Minecraft I’m pretty sure they scale the perlin height map to make it less mountainous, but the main thing they do is replace the top few blocks with something else. Desert biomes will replace the top few stone blocks with sand and sandstone, for instance, other biomes replace with dirt and grass. Flora is also spammed on top, with various decorative flowers being randomly placed on top of this perlin map, trees are probably grown in a similar method to saplings, it selects random blocks, and tries to grow a tree there if it has the space to do so.

Caves are generated by a slight modification to perlin noise known as perlin worms. A 3D version of perlin noise exists but it doesn’t “snake” very well so perlin worms were designed to instead. At this point, ores are generated by randomly randomly replacing certain blocks in a chunk with ore, then replacing more ore with an increased chance around the block.

But yea, it’s all perlin noise and it’s variations, 3d perlin noise, perlin worms, etc.

Perlin noise functions take in a seed from which their look is based off of. If you use the same seed, you get the same perlin map, thus same world.

Anonymous 0 Comments

Games that have procedural generation vary a lot with their approaches, but a great lot of them depend on RNG (random number generators) or other similar algorithms to generate objects.

These games typically have a programmed set of rules or “procedures” on what can be generated where and to what extent. From there, algorithms do the rest of the work filling in the gaps with the rules they are given. Games such as Minecraft or Terraria, for example, have pre-made structures with rules about where these structures can only spawn, and thus are generated where they typically are.

Pseudo-random generators are one subtype of RNG and they generate unique sequences using various operations and equations. Since these involve a set of operations and equations, you can get the exact same sequence if you give them the same value or number. This is one way of looking at “seeds” found in most of these games: as a sort of “starting number” or “template” to generate a specific “world” or sequence.

Space Engine, if I recall correctly, actually generates the universe with the same exact seed. This is why when you give details about a celestial body you find in-game, other people will see the exact same stuff.

Anonymous 0 Comments

It typically starts with a seed value which feeds a pseudo-random number generator in software. Those numbers are then used in the auto-generation process. Typically you’ll have sets of tables with all the different options, sometimes weighted depending on surrounding placements.

For example, if making a world with different terrain, you might have a table with all the surface types such as dirt, rock, sand, snow, water, etc. Given a random number between 0 and 100, the table might say that if between 0-40, it’s dirt, 41-80, it’s rock, 81-100 is sand.

Now, you will likely have multiple passes, and each pass may affect different aspects of the world. Often you want to have the world feel more organic, grouping lots of regions together of similar types to create the feeling of biomes or climate regions. In which case you might weight tables to rely on previous passes or on neighboring decisions. Or you might make multiple passes to smooth out outliers, replacing them with whatever is the dominant neighboring feature. Or you might even open up some of the variables to the user, so if they want to make a very random world, there’s some value which will reduce the affect neighboring terrain has on the table weights.