Sunday, February 19, 2023

Procedural Buildings: Company Names, Signs, and Flags

I've been working on a variety of smaller procedural building tasks the past few weeks. Some of these items include generating company names and family names for houses, assigning street addresses, adding building signs, and placing flags in parks and on buildings. For reference, most of the code for these additions can be found in my GitHub project in this file.

Let's start with the company names and signs because I have the most screenshots of these. I have two different name generators. Each company will choose one of these randomly with a 50/50 chance. The first one I wrote myself and selects one of ten "mini generators" for each name. The core of this uses my procedural name generator - the same one I use for planets, people's last names, and some street names. The basic idea is sort of like the typical Markov Chain string generator, except with my own custom weighted table of of letters and consonant blends. Most of the time it creates names that can at least be pronounced. If you're interested, the code for that part of the name generator can be found here.

Each name created by this algorithm chooses a random generation mode. Some of these include:

  • Only the generated name
  • The name with a random prefix or suffix selected from a list of common company name prefixes/suffixes
  • Two or three names of the form "<name1> & <name2>" or "<name1>, <name2>, & <name3>" (typical of law firms)
  • Two random names separated by a space (like a first and last name)
  • Three letter acronyms

This generator produces some odd names, but they're all unique. It also produces some interesting ones such as my favorite, "Chaos Co."

The second company name generator was copied from Shamus Young's Pixel City project, which was my original inspiration for creating these city blocks with office buildings. This generator is surprisingly simple, with only three lists of text strings and three lines of code. Nearly all of the names make sense and are easily pronounceable. The downside is that the names are less unique than my own generator, and users may come across duplicates or similar sounding names on two different buildings. Adding a mix of the two name generators produces both a good number of unique names and names of reasonable quality.

I started by placing small signs above building doors, but they tend to be not well lit and hard to read. Then I decided to place larger signs on the roofs of buildings that can be seen from a distance and while flying over the city. Each sign is placed on the tallest roof section of the building and in a location that's not blocked by any other part of the building. Some examples are shown in the image below.

Many of the office buildings in a city have signs along the top edges of their roofs. The building in the center also has a flag on its roof.

Half of these signs are randomly chosen to be emissive so that they can be seen illuminated at night. This definitely adds a more colorful and interesting feel to night time cities. Unlit signs are dark colors such as black, dark blue, and dark brown. This improves contrast against their white backgrounds and the lighter daytime colors of buildings, roads, and the sky. Night time signs are brighter colors such as red, green, and light blue. These don't show up as well during the daytime, but they really pop against the dark buildings roofs and night time sky. Some night time screenshots are shown below.

Office building signs lit up in bright colors at night.

City viewed at night, lit up by countless window lights, streetlights, car headlights, glowing signs, and antenna lights.

Next we move on to signs placed on houses. I've already added "Welcome" signs above some doors. I decided to add last names of the occupants to some of the houses. The problem is that many of these generated names are odd, and it's not clear to the user that they're actually family names rather than random text. I added onscreen messages such as "Welcome to <company name>" or "Entering the <family name> Residence" when the player enters a building, which helps somewhat. These notices may become more important later when I add more gameplay elements.

So what signs do houses typically have? How about street numbers. Great, so now I have to assign addresses to houses. I already have street names, so all that's left is assigning numbers. I'll use the typical system we have in the U.S. where even numbers are on one side of the road and odd numbers are on the other. I'll also skip some numbers between houses and office buildings. Now that I've assigned street numbers, the question is where to place the signs on houses. The easiest solution I was able to come up with was placing signs on the porch roofs, on the side facing the road. This way I don't have to worry about signs blocking doors, windows, lamps, doorbells, or other items placed on the exterior of the house. Here is what this looks like.

Houses now have proper street addresses with generated road names and house numbers. Some of them have numbers on signs along their porch roofs, near their front doors. This house is at 954 Fleincoch Street.

Next up is flags. I chose to use an American flag texture since it was easy to find and the most common type of flag in my area (and probably all of the U.S.) At first I placed flags on the peak of office buildings with tall pointed roofs. You can see one of these flags in the building in the center of the first screenshot on this page. Next, I added flags to some of the city blocks and to parks. These flags are on a long flagpole placed on the ground, with a random orientation. Here's an example flag added near the center of a residential neighborhood park.

A park with trees, benches, and an American flag on a flag pole near the center.

That takes care of office buildings, city areas, and parks. Finally, it's time to place flags on some of the houses. The most common way to mount a flag to a house is angled upward and outward from the wall near the front door. It's a bit tricky to calculate the coordinates and properly texture flags at an angle though, so I made the pole extend outward horizontally from the wall with the flag hanging down. This fits with the general cube theme I have with this project. As long as flags poles are shorter than the sidewalk is wide, I don't have to worry about them clipping through power lines, telephone poles, or streetlights. This horizontal style is less common, though I do see flags like that occasionally. Here is what this looks like on a residential road where the houses on each side have American flags.

Houses with flags hanging one poles horizontally attached to their upper walls. Everything is easier when using cubes!

 

This is a pretty good start. I would like to add more types of signs and flags to buildings at some point in the future. It might be interesting to generate procedural flags for each city, or possibly signs with procedural logos for some of the company office buildings. Those ideas sound pretty time consuming and will have to be longer term sub-project.

At this point I'm moving on to other tasks. One of these is adding config options to make buildings use consistent materials/colors, shapes, or sizes across cities and individual city blocks. Another feature I'm working on is adding skylights to office building roofs. I'll have to think about which of these will be the topic of my next blog post.

2 comments:

  1. I feel like the "countless window lights..." are actually very countable. Couldn't you put a statistics readout on the UI to show how many of each of these are being rendered at any point?

    I don't know why, but I had it in my brain that you lived in Finland or something. I see, from your comments on the American Flag, that this is not the case.

    ReplyDelete
    Replies
    1. Windows aren't rendered as individual objects. I have a custom shader that takes each building exterior wall as a quad and draws the windows. That bottom night time seen probably has a few million windows if you count the ones drawn in the background off in the distance. But it's really only a few dozen draw calls (one per material per world block) and probably less than 100K total quads. Maybe only 0.1ms to draw all of the windows? That approach is pretty limiting in what I can do with windows, but is very efficient.

      The lights (streetlights and headlights) are currently capped at 1024 visible for performance reasons. And max of 256 per world tile, which is plenty for this type of scene. 1024 is a good number because it means I can pack the light indices into only 10 bits in the GPU data, and 256 allows for an 8 bit size field. Scenes like this will almost certainly be at that 1024 cap.

      Finland? I live in the US, in California.

      Delete