Procedurally Generated Content For Games
Substituting Artistic Talent with Code
I can't draw to save my life. I've tried, but even my most basic drawings don't seem to look right. Fortunately for me (and the rest of the world spared from my terrible programmer art), I can use code to draw my content for me. Procedural content generation refers to using computer algorithms to automatically create vast amounts of content such as textures, environments and music. Games such as Spelunky and No Man's Sky and many others make extensive use of procedurally generated content to create their worlds. For No Man's Sky, a game which is set in a generated galaxy, it would have been virtually impossible to create all of the content that is present in the game by any other means due to the sheer size of the game. In this post, I'm going to show some simple examples of procedurally generated content specifically for creating variety in games.
This is what the end result will be:
You can try it for yourself here: Procedurally Generated
The above web app shows 3 different types of procedurally generated content: the background, the character, and the character's name. If you click anywhere in the web app, an entirely new set of content will be generated.
The Background
The backgrounds are generated using a function called Perlin Noise developed by Ken Perlin. It is used to give an organic look to computer graphics. By varying the x and y coordinates and the amount of noise being applied, we can achieve various effects including the ones seen above.
The Character
The character portraits are created by first defining a masking image. This mask tells the algorithm which pixels need to always be drawn (the outline of the face) and which can be filled in randomly (the ears, eyes, nose, mouth etc.) Notice that the characters that are generated have differing expressions which results from the different configurations of the eyes, eyebrows and mouths specifically. All of these characters are generated from a single mask image seen below. The final image is mirrored to give the entire face.
Names
Character names are generated by using a pattern and applying some randomness to the pattern. A name normally starts with a consonant and is followed by a vowel and other consonants and vowels in sequence. In some cases, a name can start with a vowel, followed by a sequence of consonants and vowels. The vowels and consonants are pulled at random to create the final name. In so doing, the algorithm generates names such as: Grishau, Choire, Heiw, Oshoott and Rout.
Using techniques such as these allows for an almost limitless range of possibilities when it comes to generating content for games.
Comments
Post a Comment