Procedural city based on Perlin noise


Based on a known method of creating a single random city block using perlin noise, we have created a method of procedurally generating an infinite city without the intervention of human designer.

Perlin city is deterministic, realistic and beautiful.

To achieve best performance possible, we used object pooling, separation of building objects upon multiple frames using coroutines, detecting when to create and destroy and addition of detailed objects that are displayed and hidden based on distance.

Perlin Noise

A technique used to produce natural appearing textures on computer generated surfaces for motion picture visual effects.

The basic perlin noise function receives X and Y inputs, and returns a value between 0.00 and 1.00.

public float perlin(float x, float y)

Perlin is deterministic and provides smooth transition between results of close inputs (as opposed to random noise function).

Every color represent a value on the grid.

How do we use the Perlin noise?

We have over 40 models of buildings arranged by height and type. Every value on the perlin map is mapped to a specific building and placed on the real world map.

Aftewards, a grid of vertical and horizontal roads are placed on the real world.

The smooth transitions between the values help make the city appear realistic.

Tall buildings appear together in a cluster and there is a smooth transition on the height and type of the buildings that are being placed.

Determinism

When we sample values from the perlin map to decide how to build a building block, we take the block’s coordinates into consideration.

This way when the player returns to the same spot, the same area from the perlin map is sampled and the same buildings and roads are created.

We are also considering a seed parameter, which is randomly determined at the beginning of the run, in order to get a different city map each time.

How many to build at the same time?

We use a system of Blocks. A Block is a square grid with buildings, parks and roads that has a predefined number of objects in it. Instead of building all the objects at the same frame(causing this frame to take 2-3 seconds to be rendered) we split the objects on many frames using coroutines. This way we achieve a seamless building flow without stopping the rendering of the frames.

When to build?

When player reaches a threshold distance from the borders of a block, we build a block in front of him. When player is getting too far from a block (usually behind him), the block will be destroyed.

Object pooling

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on it. When the client finish with the object, it will be returned to the pool instead of being destroyed. This saves costly allocating and releasing of memory actions.

Realism

We added walking people and cars that only appear when you are in a certain distance.

Trees also appear with a higher threshld of distance.

Every crossroad has traffic lights and bus stops.

Trees, cars and people only appear when you are close enough to them.

City background sound is heard only when getting closer to the ground.