Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Procedural Generation: The First Step

Author
Message
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Feb 2013 20:19 Edited at: 3rd Nov 2013 01:34
Procedural Generation: The First Step

I am by no means an expert in procedural generation techniques, however, from my experience there seems to be a distinct lack of information on the subject that is suitable for beginners, so I thought I'd try to cover the basic principles.

What is Procedural Generation?
As the name suggests, procedural generation is when an entity (map, object, texture, string, etc.) is created via procedures executed within the program, as opposed to being generated from static data. A procedural image could be as simple as one solitary dot, all that's required is that at least one property of the dot (x/y co-ordinates, colour) be determined procedurally. So here is your first procedurally generated image:


What Procedural Generation is Not!
Contrary to what the above code suggests, and what many people mistakenly believe, procedural generation is not random; true, random numbers are often used, but randomization is merely a method of producing arbitrary variation. If we seed the random number generator with a static value we will produce the exact same dot each time we run the code:

The ability to reproduce the same entities consistently is vital when the data being generated is too large to be stored in memory; this is what allows players in Elite to return to planets they've previously visited.

Know the Rules
Procedural generation relies heavily on rules, these rules are what give structure and form to the entities created. Our “procedural dot” has three rules associated with it:
1. Its colour must be the previously set ink colour.
2. Its Y co-ordinate must be 10.
3. Its X co-ordinate must be between 0 and 200.
The first two rules are static in this case so they might appear unimportant, yet they greatly restrict the type of dots we can produce with this code -- it should be apparent that infinitely iterating this code would produce a horizontal line of uniform colour. If we randomize the colour and Y axis we get greater variation but as a consequence we also lose structure: From herein I'm going to use for-loops to display all the possible x/y co-ordinates without having to rely on the random number generator.


Building Structure
Creating complex entities requires more than randomization, we must add complexity to our structure to allow for variation that follows a desirable pattern. One way to increase structural complexity is to make different parts of the process affect each other. This is like drawing two balls from a bag: the second ball cannot be the same as the first, this is an “emergent rule”; creating associations allows for rules to emerge procedurally without having been explicitly defined by the programmer.
If we take our previous snippet and associate the colour with the X and Y co-ordinates we get something a little more aesthetically pleasing:

It's a nice smooth gradient but we can make it more interesting by forming additional associations between the co-ordinates:
or even:

What do you think will happen if we change “x-y” to “x+y” or change “y” to “x-y”? We actually remove colour or complexity from the image because we're reducing the number of unique terms; we must take care to add complexity not remove it. So maybe instead we try multiplication:

But is this procedural generation? Yes, and this demonstrates that randomization is not fundamental to the concept: we've specified the values 0 and 255 but everything in-between is generated by the program – so technically you could argue that the four corner pixels are not procedurally generated, but the rest of the image certainly is. I will repeat what I stated before: randomization is merely a method of introducing arbitrary variation.

Here is an image of all the outputs for the code examples above:


______________________


If you would like me to continue this series please leave a comment and your suggestions for future topics (relating to procedural generation).

Cheers,

OB


If you would like to send me a donation of any amount for writing this tutorial, and to encourage me to write more, then click this button: I would really appreciate it but I don't demand it.


Formerly OBese87.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Feb 2013 01:15
@Obese87 - I've been interested in procedural generation since the ZX Spectrum after playing for months on end on Elite. I quickly learnt about the "Pseudo Random Number Generator" from the magazines that were being published then and started off early.

As you are probably aware I used the procedural randomness in the DBP ProcMap plugin sometime ago and will very likely use procedural content for a long time to come too.

When I was working on the Amiga and Atari ST I spent a long time also doing procedural music. Sometimes getting some good results too, but after a while I would store a database of "Seeds" that would generate the better collection of music it generated.

The Seed is the most important piece of pseudo randomness. From just one inputted number, ie. an int gives 4,294,967,295 possibilities, you can generate anything the imagine allows. That was proven with the ProcMap plugin. When I get around to it, I will be building another procedural level generation algorithm.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Virtual Nomad
Moderator
20
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 22nd Feb 2013 02:06 Edited at: 22nd Feb 2013 02:08
OB, do continue, please. i've tossed procedural generation around in my head but never read up on it or written any of my ideas down.

the intro above begins to give my thoughts and ideas structure, and i'm interested in that

one old game idea i have involves procedurally generated towns or cities. being able to account for each unique town/city with a single seed is, of course, ideal when i'd like them to be shared with others vs passing on massive arrays of actual, raw data.

in a nutshell, the game idea involves residential neighborhoods composed of homes with X amount of possible features set in Y amount of property (plot) lay-outs with Z amount of landscape possibilities (i would leave the primary and secondary colors of the structures "random" for variety ).

on the first block of 20 homes, i imagine HOME1 to be the seed that dictates the rest of the homes in BLOCK1. then, perhaps, HOME20 would be the seed for HOME1 on BLOCK2, and so on.

i'm not asking for example of this as i believe you already have set where you want to go with a Step 2 follow-up post. i suppose i'm simply revealing why i'm interested in its existence

Virtual Nomad @ California, USA . DBPro V7.7 . Matrix1Utils 05.27.12
AMD Phenom™ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 22nd Feb 2013 06:21 Edited at: 22nd Feb 2013 06:22
it is a good read, your points are accurate, definately keep going with this

the biggest problem i have with PG on large scales is that with enough rules to get intelligible results from a content generator wether its random or variably modular, repetition is inevitable and glaring. what use is an infinite world if everything is just a reconfiguration of a relatively few and identifable components again and again, the see one youve seen them all effect. and without enough rules or with conflicting rules you get untilligible nonsense far too often.

this isnt meant to be negative on PG, in fact i often make use of PG systems though in small scale and carefully chosen tasks. rather what im getting at is its an important consideration when designing a system to find a way to balance the 'magic vs machine, thinking vs feeling, automation vs art,' how much should actually be given over to the machine, how much should be crafted in fixed form and provided to the sytem, how much should be left to the player? how do you give true depth and soul to automation and make it more than a paper mask imitating something it has no true understanding of?

some work is best done by factories, some work is best done by craftsmen.

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 22nd Feb 2013 08:08
@Follow@


Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 22nd Feb 2013 08:35
Excellent work. You should throw in a picture.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Jun 2013 13:13 Edited at: 3rd Nov 2013 01:34
Thanks for the feedback. I've been meaning to write a second one of these for a while now, I will start working on it soon.


Formerly OBese87.
Rick the Programmer
22
Years of Service
User Offline
Joined: 23rd Mar 2004
Location: Maryland
Posted: 26th Jun 2013 04:45
Enjoyed the read and find it to offer compelling concepts. Was a gem to find while just browsing the forum's topics. Please do continue the series.

Ask not for whom the bell tolls;
It tolls for ye!
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Jul 2013 18:17
While researching for the next tutorial I stumbled across this: http://www.citygen.net/
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 12th Jul 2013 06:05
I'd love to read more on this topic. It's something I've always been interested in, but I've never been able to do it in a way that balances randomness/uniqueness with "good" results. The hardest part is having some idea of what you want - like a space station - and making an algorithm that generates things like that.

I just read a great article about Dwarf Fortress's terrain generation that relates to this. Dwarf Fortress's creator says,
Quote: "A lot of initial attempts at a world generator will start with things like "I need to lay down some forests, and some mountains, and some rivers, and some deserts..." and then when you end up with a jungle next to a desert, or a desert next to a swamp in an unlikely way, it's difficult to fix."

So instead of trying to tackle the problem at a high level like this, he reduced the problem to its simplest parameters. He generated maps for temperature, rainfall, drainage, and other things like that, then used those to create the biomes. It's easier to think about how you might generate this data, and you can then turn it into the result you want.

Sorry for rambling, but yeah, write more .

Login to post a reply

Server time is: 2026-07-08 02:11:19
Your offset time is: 2026-07-08 02:11:19