Intro to Procedural Generation.
Published: 2024-06-02 20:00:14

## Introduction
Procedural Generation is a term that may have been heard by many, but only some people are aware of what it actually is and all that is involved for it to be used effectively. It is an important method that is responsible for adding a sense of authenticity or distinctiveness to many of the games, movies, songs, and other forms of media & technology present in our modern society. Franchises like Minecraft and Lord of the Rings are a just a couple of the places where this concept has been used to improve the quality of a product.

## What is Procedural Generation?
Procedural generation, also referred to as Proc Gen, is a method of data creation that heavily relies on the combination of algorithmic methods and existing data inputs. The data created from procedural generation have the potential to be used for a variety of things that span media and art alike. A lot of the “heavy lifting” that an individual (or team of individuals) may have to endure can usually be avoided with the use of Proc Gen. With it being a subcategory of synthetic media, Proc Gen, in short aims to create a "mostly unique" result based on data modifications it makes according to provided inputs and other pre-determined values. Seed values are typically provided as numerical values to act as a guide for how "randomness" will be established. This differs from traditional data creation methods by significantly reducing the time, effort, and storage size that otherwise would have been consumed by use of manual creation.

## Key Concepts
- Efficiency: 
  * Unlimited potential for content generation with storage needs remaining minimal
- Innovation: 
  * Different uses entirely dependent on the individual's creativity
- Scalability: 
  * Can be used to create many features and change some too

## Noise
Procedural generation uses a concept called noise. Noise is a set of randomly created and arranged values that are set up in a way that produces a picture. This picture is constructed of a pixels that get modified depending on certain factors and inputs that are determined by the developer. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wi23zlfseatg8d2x7cuh.jpeg)

Each value's position in the noise being used corresponds directly to components that will eventually be combined together to have a finished product. Noise is in charge of ensuring that the unique combinations of possibilities remain different and hard to replicate. 

```
noise.seed(Math.random());

for (var x = 0; x < canvas.width; x++) {
  for (var y = 0; y < canvas.height; y++) {
    // All noise functions return values in the range of -1 to 1.

    // noise.simplex2 and noise.perlin2 for 2d noise
    var value = noise.simplex2(x / 100, y / 100);
    // ... or noise.simplex3 and noise.perlin3:
    var value = noise.simplex3(x / 100, y / 100, time);

    image[x][y].r = Math.abs(value) * 256; // Or whatever. Open demo.html to see it used with canvas.
  }
}
```
###### Courtesy of josephg's [repo] (https://github.com/josephg/noisejs) on GitHub

## Applications of Procedural Generation
Procedural generation can and has been used in an almost innumerable amount of ways that are only truly limited by the confines of what is possible with today's current technology and the creativity of the developer using it. While it would be impossible to cover every use, there are a few more common usages that many of us have been exposed to and have no idea of it.

### Video Games
The most popular usage of procedurally generated data can be observed in video games. With the help of the technology involved, many of the landscapes available to explore in certain games are created from Proc Gen algorithms. Games like Minecraft, No Man's Sky, and Terraria are just a handful of titles that make use of the method for world creation and expansion. Texture creation/mapping is another usage that allows for game textures to be made with certain guidelines to ensure that they align with their appropriate locations (i.e. rocks on the ground, scales on a dragon, etc.). Three-dimensional models can also be generated to add to the atmosphere and improve immersion (furniture, characters, clothing).

![Terraria similar to noise example](https://forum.godotengine.org/uploads/default/optimized/2X/0/082ddef006d8bf46480ed47dc81a0ae7bbc4c958_2_1380x394.png) 
###### [Terraria's pixel graphics](https://forum.godotengine.org/t/how-to-world-generate-a-world-like-terrarias/19419) make it easier to visualize how "noise" can be used to create a landscape

### Movies
Procedural generation is used in movies a lot in instances where it would be extremely time-consuming to manually design and detail specific scenes in order to "sell the illusion". Proc Gen comes into play when these cinematic scenes that may be lacking in one way or another and adding certain details (both major and minimal) may be needed. An example of this can be seen in the movie Avatar, in which multiple algorithms were used to create the alien plant life in the movie based on data pertaining gathered from real trees. Crowds of people are also generated sometimes in movies as well due to the lack of time needed to individually design or style characters.

![Avatar flora](https://lumiere-a.akamaihd.net/v1/images/a_avatarpandorapedia_04_hometree_16x9_2697_dad5ed33.jpeg?region=0%2C0%2C1920%2C1080)
###### Trees from [Avatar](https://www.avatar.com/pandorapedia/aranahe-hometree) movie

### Music and Sound
Music and sound don't rely on procedural generation as heavily but it is still used occasionally to create unique compositions based on the same principle of algorithmic logic. It can be used to bridge certain gaps in a songs melody or change it in someway as well as be used to create entire songs that are outwardly unique. 


## Challenges in Procedural Generation
Some challenges that many developers and creatives are known to face when trying to make use of this conceptual method are the ones that involve data and biases. Sometimes the data obtained to be used as an input for the Proc Gen algorithm can contain biases that may sway the desired results to be a certain way instead of being something more reminiscent of a "random" result (computers typically rely on pseudo-randomness for "randomness" in programs). Another issue that developers must be conscious of is the "procedural oatmeal" problem. 


> #### Perceptual uniqueness is the real metric, and it’s darn tough.
  > ###### Kate Compton, ["So you want to build a generator"](https://golancourses.net/2022f/wp-content/uploads/2022/09/kate-compton-oatmeal.pdf)

### 10,000 Bowls of Oatmeal
Originally explained by Kate Compton, a person is capable of preparing "[10,000 bowls of oatmeal](https://golancourses.net/2022f/wp-content/uploads/2022/09/kate-compton-oatmeal.pdf)" in a variety of mathematically different ways and preparation styles, but the person receiving the oatmeal will just see oatmeal and nothing more. This scenario was described to highlight that uniqueness is just as important as vastness. The purpose of procedural generation begins to get lost as soon as results become barely indistinguishable. Even with how expansive creations can be from the use of certain seed values, "random generations" can look very similar and may as well be perceived as the same as far as the user is concerned. 

## Conclusion
In conclusion, procedural generation is a method that is widely used by creative minds as well as tech enthusiasts alike for the capabilities it offers to whatever you can think of. With the assistance it provides by lightening the workload of indie game devs or creating funky art to look at, Proc Gen allows for users to modify and adjust their algorithms and datasets to help out with their desired task.

Sources:

- 
https://www.mit.edu/~jessicav/6.S198/Blog_Post/ProceduralGeneration.html
- https://joeiddon.github.io/projects/javascript/perlin.html
- https://golancourses.net/2022f/wp-content/uploads/2022/09/kate-compton-oatmeal.pdf
- https://gamedevacademy.org/what-is-procedural-generation/#Create_Noise_Maps_for_Procedural_Generation
- https://www.smashingmagazine.com/2016/03/procedural-content-generation-introduction/
- https://en.wikipedia.org/wiki/Procedural_generation