In this post I’ll talk a little about things to consider when using procedural placement of objects. How to produce more artistically pleasing results than simple random distribution, and incorporate this into the development of a ‘flotsam’ system to scatter detritus around the level.
The simplest approach to procedural placement is to just scatter objects by picking random locations. However, random functions are carefully tailored to produce an even distribution of values so simply using rand() to place things will tend to evenly distribute objects. The problem with this sort of placement is that it will tend to look very unnatural and certainly won’t be pleasing artistically. This great GDC talk from Kate Compton goes into some detail on techniques you can use to improve procedural placement and while I’m going to summarise things here it’s well worth taking the time to watch it through (placement starts at around 13:24).
- Clustering - this technique is exactly what you would expect. Placing small clumps of objects together into clusters looks significantly better and more natural than uniform scattering.
- Hierarchy - taller objects look much better when surrounded by shorter objects to break up sudden jagged spikes of height (unless you want to draw specific attention to an object).
- Barnacling - this is really the implementation of the hierarchy idea and consists of repeatedly placing increasingly shorter objects clustered at the foot of taller ones to smooth out the silhouette.
- Footing - this refers to the interplay between an object and the ground beneath it. If you place something on the ground then grime, dirt or detritus will tend to accumulate around it. Adding this in really helps objects look like they belong in a scene rather than just being dropped in.
- Greebling - this simply refers to “sticking stuff to other stuff” in-order to build up surface texture, detail and interest.
Now that we have a good idea of the desirable qualities we want from a placement system it’s time to set about implementing it. I’m calling this the flotsam system and intend to use it to scatter random unimportant detritus to fill in empty space around other specifically placed items.
For now I’m going to focus on just clustering but I have no doubt future posts will look at implementing the other ideas (and I guess the post on Decorations and Tiling falls under Greebling). So, since we can’t use pure random to get the results we want we’re going to have to temper it with something else. Thankfully a high frequency noise texture exhibits nice consistent value grouping and falloff while still giving loads of variety. Noise really is the Swiss army knife of procedural techniques!
So let’s build out the algorithm by starting with a bunch of ‘slots’ that could have an object placed into them, these can be as fine grained or as course as we need. Using slots makes it easy to control where the flotsam system shouldn’t place any objects, for example on top of hand placed assets or assets coming from different placement system. We do this by simply marking slots as full. Next, for each empty slot we sample into our noise texture and if the returned value is below some given threshold we can go ahead and place an object. Of course this threshold is tuneable and because of the nice value falloff characteristics of noise, adjusting it will control the size of the resulting object clumps. So we can use this to dial up or down the number of objects that actually get placed.
Note I am just using a single testing box asset here, but the system will pick from amongst many varying assets when complete.
OK, that’s not too bad, we get great clumping but things are still looking too uniform and far too dense. Here we can actually make use of random by adding a second tuneable threshold. Once we have consulted the noise map and decided to spawn an object we make a second check and only spawn it if a random value falls below this second threshold. The effect of this is to thin out the density of objects within a given clump without spoiling the clustering effect.
A final tweak to the flotsam system is to detect when objects are being placed in adjacent slots to each other and tweak their positions to move them closer together (though not so close that they intersect), and then add a bit of random rotation for variety.
That’s not looking too bad, once there is a decent selection of assets to pick from it should do very nicely. Here’s one final image in wireframe to help show the effect of clustering over the entire level.