Procedural City Generation, Part 3
My plan was to eventually swap out the temp buildings from the previous parts with nicely chunked, prefab building kits, making a sort of layer cake with ground and mid floors, topped with different roofs and frankensteined together across the city. Using prefabbed buildings would provide complete control of the interiors, which could also be broken into modular pieces and used in a similar fashion. This is a actually a really good plan.
So obviously I decided against it and opted to try and create the buildings procedurally too, because hey, why not? More importantly, it’s really labor intensive to hand make a bunch of buildings using tiles and after making one I gave up and decided to let the computer do it for me.
I created a simple set of tiles to get started, walls, doors, corners, etc. including variants for ‘closed’ buildings that wouldn’t have accessible interior spaces:
Each building was subdivided into yet another tile grid, in this case 10x10:
And then subdivided again based on its total footprint, so at a minimum each space consisted of at least 2 actual buildings:
I won’t go into crazy detail here on how this gets laid out because most of it builds off the concepts used to layout the city (considering corners, edges, etc.) The next step was to start substituting correct pieces and fitting them into place:
Then I started to add in some variation in sizes, starting on the x axis:
Then adjusting the Z size so that buildings would jut out in relation to each other and create a natural back alley behind them:
Add in windows and doors at random intervals, ignoring shared walls:
Finally closing off the structure with a floor and ceiling/roof. Notice how some buildings lack interiors, while others have front doors but no back exit:
Then I built off the footprint of the bottom floor to grow vertically, using randomly sized ceiling pieces to alter the Y scale of the buildings:
Interiors looking out to the street:
Overall the city has a nice density to it, with a good mixture of interiors and negative alley space created for the player to explore:
I’m pretty happy with how this is looking! Just to be safe, I should probably check how the overdraw looks on th...
ohhhh, right. Right. Riiiight. So all those interior spaces have backfaces and windows and doors and thousands of tile pieces and, well, we have a problem don’t we? This is only one grid too, for a city we’re talking 4+ of these and since we’re already killing it on performance, imagine all those layered in above?
The trick with dynamically generating content is that while you gain flexibility and variety, you give up the built in controls the engine provides for optimization, features like baked culling volumes. But before all that, I absolutely need to clean up my tiles, starting with eliminating backsides for exterior-only locations. I have to consider eliminating tiles in repeating sections and scaling instead, as well as seeing if I can do something about sharing repeated vertical geo. I most likely will have to write a system to LOD/impostor buildings in and out when they’re not in view or at distance. Ultimately, this is going to require a few different solutions working in concert and some mindfulness going forward on performance. If it’s struggling with my simple tileset, imagine the hit when I have actual geo in, plus textures, cars, AI, sound, fx, lights, etc etc...