Procedural Generation

Work

Moving towards using the procedural generation of terrain as a useful tool for games, I first started creating simple meshes on Unity and soon moved to creating hex meshes using Red Blob's tutorial on hexagonal grids as the base for how to calculate how to layout the terrain.

Unlike previous efforts, this time I use a function mapped on the x-direction (cos(x) + sin(x)) and another on the z-direction (sin(z)+cos(z)) to calculate the height for every hex in the grid, instead of starting with Conway's Game of Life. These functions can be changed to produce different results.

This was also a great exercise to learn about shaders, which are used to determine how to color the mesh. Beneath a certain threshold, the shader simply outputs blue (as a sort of sea-level cut-off). Above that threshold, the shader adds the values for the normals of the mesh to color the "land" portion of each hex. Since the normal in Y is green, it works out great to make it feel that these are grass topped hexes.

Moving to Unity

Meshes, noise & shaders

My most recent project for terrain generation involves first creating an image using Perlin Noise which I use to create colored terrain. The terrain and original noise map are fed to a shader which computes shadows in real-time.

In 2018, I started a blog called Eduardo Builds where I shared the projects I worked on in my spare time. During the time I maintained that blog I worked on two procedural generation projects.

The idea behind this project was creating mazes that combine rooms and corridors to then populate them with the encounters I'd give my players.

The first step in developing this was first creating perfect mazes, for which I implement a version of Prim's algorithm in Javascript.

After that worked, I used that technique to fill the spaces between randomly created rectangles that served as the rooms for the dungeon and then opened doors between the corridors and the rooms to make the design feel more connected.

I continue to work on this tool, with the idea being to also randomly generate denizens of these dungeons that form factions and have claimed parts of the dungeon for themselves. It can be found here.

Having seen it was possible to create two-dimensional terrain using cellular automata, I tinkered with ways of procedurally generating height values that would allow the creation of 3D masses that felt usable in simulations, mesh generation or creating visualizations for DMs of their worlds. It was also a great excuse to practice the R programming language, which I was using while practicing Machine Learning.

The terrain generation and the height values were created using Javascript on a web browser system I no longer host (though the code can be found here). I then exported the array values to R for the visualization.

This served as the basis for my latest project in procedural terrain generation using Unity, discussed below.

Dungeons & Islands

Previous Work

One project was about creating dungeons procedurally, inspired by my need to create content for the D&D group I used to DM for. The other one was a refinement of the Cellular Automata project from 2015 that sought to generate realistic-feeling three-dimensional terrain.

The dungeons

The process

A possible dungeon

A heat map for height

Same terrain visualized in R

The islands

A heat map for height

Same terrain visualized in R

The process

A possible dungeon

First steps

One of my earliest projects as I tried to learn how to program was creating a grid of terrain procedurally.

Noise
Noise
Cellular Automata
Cellular Automata

From noise to cell systems

The two images below are my first naïve attempt at terrain generation using Markov chains and then using Conway's Game of Life with an adapted ruleset. These images are both from 2015. Sadly, I lost the code to this specific project when the HDD in my computer failed.

Pure noise

Cellular automata

Cellular automata

Pure noise