Procedural generation — a broad and massive topic that can seem intimidating at first, but whose fundamentals can easily be grasped and replicated. It is the algorithmic creation of data, or more simply, an automated process with a set of governing rules.
You will have seen this via landmass or level generation in popular video games like Minecraft, Spelunky, and No Man’s Sky, to name a few. In animation, Lord of the Rings used proc-gen to simulate its armies, and the Mandalorian uses it to produce landscapes. Outside of computers, nature has its own processes by which ordered logic is executed.
The important concept to grasp here is: processes following rules, or rules that we follow.
Think of how you’d shuffle a deck of cards. You might take some cards from the ends and put them into the middle, or fan two stacks of cards into one, or spread them out on the floor. Your shuffling process follows rules to achieve your result, the perception of randomness. The same goes for all procedural generation processes, just with more rules.
One early and powerful implementation of procedural generation uses cellular automata to display seemingly organic patterns and structures. It’s called Conway’s Game of Life¹.
A cellular automata is a grid of cells, with each cell having a finite number of states such as “on” and “off”. The Game of Life is an incredible demonstration of the potential of procedural generation using cellular automata. Following four simple rules, each cell’s fate in the next “generation” is decided by its neighbors.
Break out of computers for a second and let’s take a look at how some of the rules in the Game of Life govern our very selves in nature! Take this study on the ocellated lizard for example.² As a lizard ages, its skin begins to take on a different pattern of pigmentation. Looking at the adult lizard (B), we can see a labyrinthine pattern has emerged from a spotted one (A). There must be a set of rules through which one pattern emerges from another. We don’t have to know all the rules to grasp the significance, just look at slides H and I. Look familiar? Certain cells have de-pigmented because they were deemed as having too many neighbors. Conway must have drawn inspiration from natural processes like these.
Back to computers… How can we extend this logic in a useful and demonstrative way? Let’s take our cellular grid, our basic Conway rules, and add to each cell in that grid an initial chance to activate. You can study and tinker with one such demonstration, and even code along to make your own in Unity in the link below.⁴
We can start with a grid of randomly activated cells (think noise) and through each generation of our procedure, they begin to take on a seemingly organic structure. To further demonstrate the value of similar processes, let's take a look at what's called Perlin Noise.
Perlin noise is a type of coherent and gradual noise used to visualize realistic and organic appearances. Just like our randomly initialized grid of cells but:
- Instead of cells being “on” and “off”, we have values ranging between 0 and 1, best referred to as height (think darkness, or intensity)
- The cells follow the ever familiar rule of gravitating towards one another and not existing in isolation or excess (neighbor rules)
- Lastly, neighbors have a tendency not to change from one height extreme to the opposite, except in a gradual manner: something of an extension on our isolation rule. Notice the transitionally fading appearance.
It might look nonsensical still, but let’s make use of this by coming full circle. One series of incredible Unity tutorials later⁵, we can coordinate the height values in our Perlin noise map to colors in a familiar pattern, like landscape.
We take a map like the one above, and we make some decisions on which values should be what color.
Remember our values range from 0 to 1. Start with our two geographical height extremes: deep seas and mountain peaks.
Assign colors and values to everything you want in between: shallow water, beaches, land, rocks, mountains.
Watch our coherent noise map turn from chaos into a familiar appearance.
From the appearance of chaos, through the obedience of a set of rules, comes the appearance of order.
One last important thing to note regarding the simulation of randomness is the concept of seeds. Through the use of seeds, we can dictate to our simulations the order in which they randomize their behavior. Using a seed, you can control and store results, which is useful in:
- Debugging procedural logic by reproducing and analyzing
- Saving random results in video games for multiplayer competition
- Storing massive worlds just by saving their seed and the algorithm that produced them. Think of an entire galaxy, reproducible by merely plugging in an integer.
When it comes to procedural generation, remember what was reiterated most here.
- Sets of governing rules with which we can automate processes
- Maps or grids populated by cells who have some defined value
- Organic neighbor rules: Cells attract other cells, they mostly do not exist in isolation, and they tend only to change gradually
When you observe an organic structure in nature in the future, try to pick out a few of the rules they followed to arrive at their result
It is well worth diving into any of the tutorials or articles listed below if you’re interested in learning about or doing this yourself. This only scratches the surface of procedural generation. It’s important though, not to forget, that whether it’s leopard spots, honeycombs, fish scales, lava, camouflage, clouds, or landmasses, it’s a set of governing rules that can be picked apart and imitated if done carefully.
2 — Manukyan, L., Montandon, S., Fofonjka, A. et al. A living mesoscopic cellular automaton made of skin scales. Nature 544, 173–179 (2017).