Friday, June 21, 2024

Procedural City: Additions and Improvements

I've been considering adding another form of transportation to 3DWorld's procedural cities. Maybe elevated monorails connected to the upper floors of buildings? I could possibly reuse the existing walkway/sky bridge system to connect to the monorail. But I'm not sure how to do this yet, so it will have to wait until another post.

The past month has been mostly bug fixes and smaller incremental improvements to walkways, hotels and apartments, and cities in general. I'll list the additions and improvements here, along with some screenshots. The majority of my bug fixes aren't really visible and are probably too boring to mention.

Hospital Emergency Signs

I showed white and blue hospital signs placed outside hospital doors in a previous blog post. The problem with these signs is that they're small and difficult to see, especially in the dark. Now I've added emissive "Emergency" signs that are much easier to see due to their bright color and high contrast with building textures. These signs are visible in shadowed areas and at night time. I still think there's more work to be done with hospitals, though this addition improves them incrementally.

Vooj Hospital now has an illuminated (emissive) "Emergency" sign that's visible during both the day and night.

Police Cars and Ambulances

Something about adding those emissive emergency signs got me thinking about ambulances, which got me thinking about police cars, which got me thinking about flashing lights. This seemed like something that was easy to add and would produce a great night time visual effect.

I started with police cars, since I already had a police car model that was used on city streets. This model has geometry for the typical red and blue rooftop emergency lights. I used a combination of the existing code for headlights and brake lights to implement this. Police lights alternate between the red and blue sides, where each side is modeled as two wide area spotlights. One half faces to the front and the other half faces toward the back for a nearly 360 degree coverage area. I added a shadow map to each face, which may not have been required, but definitely improves the look. This also avoids having the lights affect the car interior.

I then added an array of four adjacent circular blur billboards to each front/back side of the light that's currently lit, and later added an additional circle to the end of the light. These use the same code as car brake lights, except that the blue light has a different color. The array of four merge into a bar pattern with additive blending disabled. The total set of 9 lights form a three sided illuminated rectangle. Here is what these additions look like in a night time city.

Police cars with shadow casting flashing lights at night. The car nearby has its red light on while the car in the distance has its blue light on.

Only one in four police cars is in emergency mode with flashing lights. Half of these also play a siren sound when close to the player with volume based on distance. The siren is somewhat annoying, but limiting it to 1/8 of the total police cars made it relatively rare. None of the parked police cars have active lights or sirens. Police cars will turn their lights and sirens off if they park, then turn them on again when leaving the parking space.

At this point I had police cars and hospitals, so ambulances were the obvious next addition. It was relatively easy to find a free 3D ambulance model online. I went with a lower polygon detail model this time because some of my other vehicles have too many vertices and hurt the framerate on lower end systems. My process of adding a new vehicle is streamlined and takes only ten minutes or so. All I have to do is add a line to the city config text file listing the model filename and various numerical parameters. Here is what these ambulance models look like when driving and parked.

The new ambulance model with four visible in this scene. It's somewhat low poly and low texture resolution, but this means it's fast to draw.

You'll notice that this parking lot has a roof. I'll explain this part later.

I added lights to ambulances as well. There are a total of 14 of them, all red. I used a light schedule that cycles between various combinations with an average of three lights on at any given time. This produces a seemingly random pattern of quickly flashing red lights that should be convincing to the user. Each light has a single red emissive circular billboard, including the ones that are more bar-shaped. It was quite a bit of effort to manually assign each light to (x, y, z) coordinates offset from the center of the model! Here is what this looks like in action.

Ambulance with flashing red lights at night time. This one is stuck behind a truck at a red light.

Ambulances also use the same siren sound as police cars, which is enabled in 1/8 of the ambulances. Police cars and ambulances in emergency mode currently behave the same as other cars, with a few exceptions. They're allowed to run red lights and have priority at stop signs. However, they often get stuck behind other cars waiting at traffic lights and can't go around because there's only one lane. At some point I may change their destinations to be hospitals when in emergency mode, then have them turn off any lights and sirens when they reach it. Maybe I can even add police stations.

Here are some videos showing the flashing lights and sirens in action in night time scenes. I made improvements to the lights between the first and second video. In particular, the first video doesn't have emissive quads enabled.


 


Interior Windows

Some of the screenshots in the previous blog post showed apartments and hotel rooms without windows. This is unrealistic for rooms such as bedrooms. I'm happy to say that I've now added interior windows to city buildings, including offices and residential buildings. These have the same window frames and blinds as houses. The windows aren't visible from the outside though, because they don't correctly line up with the exterior building wall textures and night time window light patterns. I'm not sure if this will ever be fixed. You can think of them as reflective, tinted glass. I somewhat like the look of the custom exterior textures, and the variety I get compared to the non-city buildings with their regular pattern of nearly identical windows.

Hotel rooms with windows, blinds, and matching beds. The blinds are closed on the window near the center of the screen. Maybe lighting is too bright?

Office buildings have interior windows as well. They have frames but no blinds.

City office buildings now have interior windows with trim, though the exteriors of the buildings still appear to be windowless.

Even non-rectangular office buildings have windows. Sometimes these windows are placed on curved walls. I haven't figured out how to add window trim and other effects on these curved windows because trim only supports axis aligned boxes, so these windows look somewhat bare. I feel like they still add a lot of value to the city and make it easier for the player to keep track of their location and orientation.

Even city buildings with angled and curved exteriors have windows. These windows can also be curved, but they currently have no frames.

These new windows also give great views of the night time city lights! Police and ambulance lights are visible from windows, but they don't shine through them into the building. I'm currently using a different lighting system for building interiors vs. city exteriors, so the lights can't interact between them.

Improved Walkways

I wasn't too happy with the state of walkways in the earlier post. Adding windows actually caused even more problems, because now I had windows clipping through walkway doors. The system in place that adds windows to exterior building walls was only designed to handle exterior doors on the ground floor. So what I did was to draw the doors on top of the windows, and clip the window trim to the door bounds. This looks somewhat odd, but I don't think it's too bad. I certainly like how the player can now see out onto the walkway through these windows even when the door is closed. Maybe it would be better if I could center the door between two windows?

But this definitely complicated the code. Now I had to handle drawing of lights, walkway interiors, exterior doors, and window trim that may be visible even when the walkway door is closed. This was more of an optimization problem though, since I can always fix it by drawing everything all the time. Instead, I enabled the drawing of these features when the player was in the room connected to the walkway door, which worked well enough. I later extended this to include any room adjacent to the walkway that could have a window looking into it. It's not perfect because the player can occasionally see through walkway windows from an adjacent room's open door. I didn't even realize this was a problem until I intentionally tried to find a building room layout where this was possible.

While I was working on these windows, I also added a darker trim around the windows inside the walkway itself. This trim matches the trim used in the main building windows. Here is what these changes look like.

Walkway interior visible through windows in an adjacent room. All windows have dark trim. Should the door trim be dark gray rather than white?

Later I made some other changes to allow the light to pass through an open door from the building into the walkway. The door frame, door, and player all cast shadows into the walkway. This effect isn't too noticeable in the day time since the walkway is already pretty well lit. I made this change after writing the bulk of this blog post, so you'll have to wait until later to see a screenshot of it.

Solar Parking Lot Covers

My next improvement was to add roofs to some of the city parking lots, and place solar panels on top. I'm not quite sure what made me think of this addition. The roofs and panels are slightly sloped to face the south, assuming they're in the northern hemisphere. East-west oriented roofs have a randomly selected slope sign. I place roofs over a random 40% of parking lots with the height of the lower side tall enough to fit the truck model. Parking lots aren't placed under other objects, so they should only see shade from the nearby buildings. Here are some examples.

Some parking lots have roofs with tilted solar panels on them.

Each roof is held up by four square metal poles at each corner. These act as collisions objects for the player and pedestrians crossing through/by the parking lot. It did seem a bit odd to me that very long roofs had only four pillars, so I added more of them. The constraint is that the pillar must fit between parking spaces to avoid blocking them, which means I can only add them to lot sizes that are multiples of 2, 3, 4, etc. Any lot size with a prime number of parking spaces such as 11 or 13 only has the original four corner supports.

More parking lots with solar panel covers. Some of these have more than four support pillars.

I had to add extra logic to avoid placing trees that may overhang the roofs. This will avoid both the problem of leaves clipping through the roof and trees shading the solar panels.

Improved Doors

I've had that same interior house door texture in every building for a few years now. One reason I kept it is because it's so difficult to find a free high resolution texture of a clean door that doesn't have any lighting or shadows on it. Nearly all of the door textures I found look like someone took a photograph of an installed door in normal room lighting conditions. But now the strange look of house doors inside office buildings has finally convinced me to use a different door texture. The texture I chose has uniform lighting and no shadows, except at the very corners of the door. This actually looks quite good when the door is closed, but the dark edges aren't convincing when the door is open. I tried to edit it with the Gimp image editor but wasn't able to improve it much. If I adjust the color histogram to remove the shadows it will also remove the door handle and key hole. Oh well, I guess the user can always think of the door has having a darker edge trim.

Office buildings have new door models that look less like house doors, though they have dark edges when open due to the shadows on the reference image.
Unfortunately, neither of these door textures look that good for rooftop doors at the tops of stairs that the player can use to get onto the roof. I did have a texture of a double metal door with window slots that I was using for the back doors of office buildings. So I cut this in half and used one side of it as the rooftop door texture. I also added these upper stairs sections and doors to non-cube shaped buildings. Now the player can get onto most building roofs.
Rooftop doors are now metal rather than wood, and they're added to non-rectangular buildings. The white rectangle on the right is the back of a company sign.
Some buildings still didn't have player roof access. This may because the building was too small or irregularly shaped to have an interior, or because there was no valid location to place stairs that could reach the roof. Normally this is fine, but it felt wrong for those buildings with helipads on their roofs. How is anyone supposed to get to the helicopter without roof access?

My solution was to add a fake door. First I placed a tall rectangular block somewhere off to the side of the helipad, then I added a door to the side facing the center of the building. The player can't use these doors, but that's fine. There's no way for the player to get onto these roofs anyway! These were only meant to be seen from above in "flight" mode.

This is a fake door that leads to nowhere. The player can't use it, but it gives the illusion that this helipad is reachable from inside the building.

Conclusion/Summary

That's it for this post. There were other smaller city and building additions, but I feel like I've reach my screenshot budget for a single post. I need to make sure the page loads quickly.

Maybe next time I'll have something to show for the sky monorails I'm considering adding. (If not I may need to edit this post to remove this comment!)

No comments:

Post a Comment