Procedural City, Part 5: Fixes

 By Shamus Apr 20, 2009 33 comments

The time spent contemplating the program did not go to waste. I was able to correct several things that had been bothering me.

Building Textures

I mentioned before that I had two approaches to making the building textures: One would light windows completely scattershot. Each window had a fixed chance to be lit or unlit. The other approach was to light them in horizontal groups, so that the lit windows would always be grouped together.

Stepping back and looking at what I’m trying to simulate, I can see the scattershot doesn’t make much sense, and doesn’t seem to match what we see in cityscapes. Worse, all buildings had the same percentage of lit windows, which made the view even more monotonous.

All buildings should exhibit some level of lit-window grouping. The only difference from one building to the next is in how big each office / apartment is. Also, not all buildings have the same ratio of lit windows to dim ones.

So I replaced the old window-generating code with a new one. It randomly decides at the outset how big the interior spaces are, and what percent of the windows should be lit.

Now different buildings have different window shapes and different densities of lit windows and different group sizes. The city lights now look less like uniform noise and more like chaos that springs from complex ordered systems.

Tower Buildings

As I mentioned in the post on building shapes, my classic tower-style buildings weren’t going to cut it. I was supposedly making these buildings with elaborate stonework. My goal was to present the outline of such a building and allow the viewer’s imagination and prior experience to fill in the blanks with engravings and such. But I didn’t leave any blanks for them to fill in! Every building was all windows, edge-to-edge, top-to-bottom. I tore out the old code and replaced it with a new building generator:

pixelcity_building5.jpg

These new buildings are very rarely covered in windows. They have vertical stripes or windowless areas running down the face of the building. The buildings are broken into tiers, and there are a few blank floors between each tier. It begins at the bottom, drops a tier into place, then puts a lid on that tier, then builds a new tier on top of the lid, onward until it reaches the planned building height.

I love the new one because it has a ton of parameters that govern the shape of the building:

  1. How tall each tier is. (More accurately, how much of the remaining height is given to the current tier. One-half, one-third, one-forth, etc.)
  2. How much (if any) the lid sticks out from the side, forming a ledge.
  3. How tall the lid is, in stories.
  4. If the corners of the building are explicitly windowless.
  5. The grouping of the windows and blank areas on the face of the building.
  6. If the tower gets narrower towards the top.
  7. The window texture used.
  8. The tint of the window texture, from a handful of various types of light sources.

These values allow for a huge number of meaningful changes to the shape of the structure, giving the world a ton of visual variety. Also, the vertical blank areas seem very subtle, but it’s shocking how the eye can instantly spot the break in the pattern:

pixelcity_building6.jpg

Modern Buildings

These buildings looked fine to begin with, but they didn’t have a lot of variety. A slight change brought about compelling results.

pixelcity_building7.jpg

Instead of just randomly cutting off sections of a cylinder, it chooses to do so at regular intervals. And it can make cuts in 45 degree sections as well as 90. And as with the other buildings, I added some vertical window gaps. Although, it doesn’t really make the buildings that much more interesting.

pixelcity_building8.jpg

They look interesting in wireframe, but without the lines one deformed cylinder looks much like another.

Other Changes

As you’ve probably noticed in the screenshots, I’ve added a few polygons of roof clutter to hint at HVAC systems and whatnot. The building colors are now limited to a handful of hues that match common lights. And I put larger gaps between buildings, which gives their silhouettes more opportunities to stand out.

A few improvements to the existing systems made a big difference to the overall appearance.

201333 comments. Hurry up and add yours before it becomes passé.


  1. Mike Lemmer says:

    Watching these fixes come to life is much more interesting than it has any right to be. Maybe because it combines lessons on architecture and visual perception in a practical manner.

  2. Ingvar says:

    I was actually wondering if a really simple statistical approach would work well for generating “interestingly-grouped windows”, two tweakable parameters. Going from left to right along a floor, start by having the first window lit or unlit with p(lit)=0.5 (tweakable), then have each following window be the same as the previous window with p(same) >= 0.5, that should, on the whole, generate runs of windows with the same light state, but still vary per floor.

  3. Henebry says:

    Nice changes to the traditional buildings.

  4. Rowan says:

    Your project is insanely interesting, probably because even though I’m a programmer by vocation I mostly do server side stuff and have never done any 3D programming. Second, because my wife is an architect and it kinda rubs off on you. Even though I’m more interested in city planning which my wife cannot stand… go figure.

    (And it goes both ways too, I know Mies van der Rohe and she knows Turing machines.)

  5. Gary says:

    THese new forms are an excellent move toward higher realism! I really like how you tackled the “traditional” buildings!

    You could totally design an algorithm that would create an ideal building/living space that would put many modern architects to shame :) (I am very sad at the direction modernism and post modernism have taken us. They attempt to be utilitarian, but turn out to be ugly AND un-usable)

  6. Kasper says:

    So show us a city already! The newer buildings look nice and you say they make a big difference to the overall appearance, but we haven’t seen the new overall appearance yet. I can’t wait to see another big city as a benchmark for how far you have come right now.
    Or are you waiting for the final version before showing off your new toy?

  7. Mari says:

    Just to prove how universally appealing this series is, the grammar police have arrived. Second paragraph under “tower buildings” (located below the picture) contains the following: “It beings at the bottom, drops a tier into place…”

    And yet, I’m compelled to admit that while neither programming nor city planning/architecture are particular interests of mine this series has endlessly fascinated me and I’ve eagerly followed each post, even going so far as to look up concepts I don’t understand. I really like the improvements you’ve made. They have a more realistic look to them, especially in the tower buildings. I was able to suspend disbelief before to accept them as real but now there’s very little suspension even involved.

  8. Mark says:

    I had a thought about what could be added to the individual window images: blinds. Not curtains drawn from the side (though those would work as well), but blinds drawn down from the top. Seems like they’d be really easy, just darken from the top a random amount, with a distribution where all-the-way-open and all-the-way-closed are the most common.

  9. Ritch says:

    If you plan to illustrate the cityscape from a bird’s eye POV, the tops of a lot of buildings usually have some form of lighting to outline the roof features. Also, many buildings have various arrays of antennae or lightning rods. Some even have radio towers.

  10. Alan says:

    Hmm, anyone know where you can get cheap programming lessons?

    This series, along with the terrain one really make me want to lear to create stuff on the small screen – rather than just sit and play on it like I normally do.

    Interesting in so many ways.

    Thanks for putting this online.

    -Looking forward to your next project already…

  11. elias says:

    Maybe antennas with blinking lights on top of some buildings?

  12. Jericho says:

    I know how much of a pain it is to throw out code, but the improved system is superior.

  13. stringycustard says:

    @Alan Try http://nehe.gamedev.net/ There are tuts on the left. Highly recommended. He explains things very clearly – it’s what I used to get me started in opengl.

    Shamus, I’m really loving this series. Have you given thought to the city planning issue (grid-based)? Like you said time constraints make it difficult but maybe you could do a cheap form of zoning, like in Sim City 1: you declare an area residential and only have very short buildings generated there, tall buildings in cbd, short but long/wide buildings in industrial zones. You could leave large areas to simulate parks, etc. This might be faster and still fairly real looking at a glance instead of doing angular or circular city planning. Terrain height sounds fun at first but may get kinda tricky to do nicely (working out base placements of buildings so sections don’t end up floating and so on) – most cities are fairly flat anyway, or at least areas of construction are – so it could still be fairly realistic to have large flat areas of buildings and sloped (empty) areas leading to the next plateaux.

  14. droid says:

    @Alan: If you want to learn to program, just choose a language and find stuff on the net to show you how to run it.

    It doesn’t matter too much what your first language is, because other languages will have simmilar concepts. I would reccomend either C (very low level language) or python (very high level language). Learning another language is much easier once you know the basics.

    Having chose a language, google: “learning foo” where “foo” is the language chosen.

    The most important thing about learning to program is to write programs, get them working, and understand them. Python is good in this regard because all you have to do is install it and you can type code in the interpreter and see what it does immediately. On the other hand if you are using a good IDE in C++, C#, (such as Microsoft Visual C++ or XCode) then there is a debugging mode where you can step through the code line by line and see what is happening.

    I assume that you are interested in making games.

    As far as a language that is easy to do games or 3d graphics in, choices are C++ (OpenGL), C#(XNA, see RB Whitaker’s wiki), and python (pygame and pyopengl).
    There are most likely other good choices that I am not qualified to talk about.

  15. gorthol says:

    I guess I’m being greedy, but I’ll have to second Kasper’s comment. I’d like to see a whole cityscape with the new improvements, but I guess I can wait. How many parts are left before the series is complete?

  16. It looks really good, Shamus. One thing you should add to the roof clutter, though, is the occasional large spike with bright red and white lights, particularly on taller buildings.

    You might want to think about the fact that many skyscrapers nowadays make use of exterior lights, so the occasional neon stripe or bright light shining down from a building corner or up from the street can make a big difference. You would have to add texture (not at the distance this is likely to be viewed from), just a random-shaped parabola of “lit” area that is gray, yellow, or orange.

  17. Yar Kramer says:

    Wow. This is looking more awesome than ever. I’m genuinely impressed with how this is coming along.

  18. MintSkittle says:

    I’m gonna second adding lighting to the rooftops, because most modern skyscrapers have rooftop lights to warn low-flying aircraft where the roof is so they can avoid a collision.

  19. Cybron says:

    The blank spaces definitely add a lot to it. It is interesting how our minds instantly jump to blank spaces.

  20. Patrick says:

    One suggestion: If you want the modern rounded skyscrapers to look more interesting, you need to cut away sloped sections horizontally on some buildings. For example, the building may be a cylinder at the base and then have a chunk taken out, coming to a sharper angle at the top. Windows can continue along the sloped wall.

    It also might be a boxy section and then another, rounded section on top (though the reverse is rare and ugly).

    dding semi-randomized shapes like a dome or a pyramid to the top of either traditional or moden skyscrapers would also drastically improve things, but of course, we’re getting into “should I or shouldn’t I spend the time I have on this aspect” territory. Regardless, this is an absolutely amazing series and I heartily congratulate you for doing it.

  21. Yonder says:

    I have enjoyed this series immenselly as well, being interested in programming, procedural generation, city planning, and architecture (in that order). I had a handful of possible tweaks that I don’t think have been mentioned.

    1. A very small percentage of buildings could have helicopter pads.

    2. If LA is any indication, sides facing freeways sometimes have 5-6 floors of windows missing for a billboard.

    3. Buildings owned largely by one business often have the name of the business extruded out on the side, well lit even in the night. Procedurally generating business names probably isn’t a good use of your time though. And doing things like a single letter logo may not look right.

    Keep up the great work Shamus, good luck.

  22. I’m not sure how important this would be in a project like this, but just as a side note in a lot of cities there are code requirements that state tall buildings must set-back a certain amount so that sunlight can still reach street level through the day.

    That’s why many of the classic old buildings are shaped the way they are.

    http://en.wikipedia.org/wiki/Setback_(architecture)

  23. Korivak says:

    You seem to have lost the old “Sears Tower” style that you describe in your third post in your rewrite of the code. I think that adding that back in would add some interesting variety. Just remember, the bottom is always the widest part, so it would be easier to code by taking a rectangle and subtracting areas from it instead.

    http://en.wikipedia.org/wiki/Setback_(architecture)

    Also, I think the ground story “caps” should have their own style of windows. Brighter, always on, maybe two stories tall, with more colour variety. This could represent the shops and elaborate lobbies that tall building often have. You wouldn’t see much of it because of the canyon effect of the towers, but it would make for interesting little splashes where you could.

    And finally, little flashing red or white lights at the corners of the buildings and on the roof clutter would be an easy addition that would add a lot to both believability and to visual interest. Splashes of brightly coloured light projected on to the sides of your showcase skyscrapers might also be fun, since several iconic towers are so lit.

  24. Julian says:

    I love this. I absolutely love it. I’m going to college next year to study Software Engineering (rather, it’s equivalent here in Buenos Aires, called Ingeniería en Informática), so this is very, very fascinating for me. The college I’m going to (Austral) was very good at showing what types of projects students could do during the 5 years it would take to finish the course, but not a single one of them had such a thorough explanation of the whole development process. I mean, looking at a finished project was pretty interesting, but this whole “how I started, what worked, what didn’t, and how I fixed it” approach beats it.

    That said, here are some suggestions: most buildings have lights on the outer rim of their roofs, mostly to signal helicopters that they really shouldn’t fly into the building. Speaking of helicopters, perhaps you could add a square made of flashing red and white lights in the middle of some flat-topped buildings to hint at a Helipad. Also, as many have said before, antennae towers, wider streets to suggest highways and avenues, and maybe a random chance that Godzilla will appear in the city.
    Disregard that last suggestion.

  25. Rutskarn says:

    This is already starting to look drastically more realistic. Can’t wait to see a full panorama of this.

  26. Kell says:

    Nice stuff, Shamus.

    Just want to add another voice to the ‘rooftop lights’ suggestion.
    I think features like masonry trims and billboards are too restricted and specific for the simple procedural approach you’re taking. But summit lighting is a visible characteristic of most city-at-night photos I’ve seen, and would probably be quite a cost effective addition in relation to the work and rendering required to add them.

  27. roxysteve says:

    It’s interesting that this project “needs” to use the same techniques to “paper over the gaps” that trad. SFX model photography does. See: The Bladerunner documentary footage for how they made the cityscape at the start, and why the street set looked like it did.

    I remain totally gobsmacked over how much innate clever this sort of thing needs to pull it off. Like so many things in real life, it always sounds easy to do. Shamus, you are obviously worth your paycheck.

    I did notice that the perspective seems off in one of the building row tests, but hey, it’s a test and I have no idea how to fix whatever Mr Eyeball is telling me is out of skew. It’s still extremely clever. I’m particularly impressed by how you keep coming up with simple sounding fixes to what presents as a complex problem. And all without any mind-altering drugs too.

    I’d hate to have to do a mind-meld with your twisty brain.

    Keep on showing. It’s amazing.

    Steve.

  28. MOM says:

    You should teach. Vo-tech?

  29. John says:

    Like what Patrick said. With the modern buildings you could try adding steps. Start creating a cylinder that is a random percentage of the height of the building. When it cuts off a chunk make it step up to the next level if needed.

    I don’t know how hard that would be or if it would be worth it but it is an idea. Probably adding lights to the roof would define the shape more and make them more individual so it might not be necessary. You may need to add some greebles.
    (http://en.wikipedia.org/wiki/Greeble)

    I agree that signage would not go astray. Probably should be a small image, one word or both. Maybe not worth it for the purpose of this activity. They could be added in later to fit whatever the story called for.

  30. [...] 3: Generating Buildings – Procedural City, Part 4: City Planning – Procedural City: Intermission – Procedural City, Part 5: Fixes – Procedural City, Part 6: Sky – Procedural City, Part 7: The Street-Level Trap – Procedural City, [...]

  31. JP says:

    RE: “They look interesting in wireframe, but without the lines one deformed cylinder looks much like another.”

    To make their buildings more prominent in the night skyline, some office towers highlight them in neon light:

    http://www.flickr.com/photos/13453262@N03/3245965686/

    This could be mimicked by drawing a bright neon line down the tower from the top (but not necessarily all the way to the ground) on either side of a “cut”. It could help differentiate the modern towers.

  32. Great article and it is worth mentioning that Mini blinds are notorious for collecting dust. Their horizontal position creates a flat surface for dust to land on. In addition, they’re almost always next to an open window, bringing in extra dust by means of the breezes.

One Trackback

  1. [...] 3: Generating Buildings – Procedural City, Part 4: City Planning – Procedural City: Intermission – Procedural City, Part 5: Fixes – Procedural City, Part 6: Sky – Procedural City, Part 7: The Street-Level Trap – Procedural City, [...]

Leave a Reply

Comments are moderated and may not be posted immediately. Required fields are marked *

*
*

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun.

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!