Thursday, September 5, 2024

Updated Water for Swimming Pools and Flooded Basements

I've been working on water rendering for indoor and outdoor swimming pools and flooded basements on and off for the past month or so. This has been going on in parallel to my work on interior dirt and damage, escalators, and glass floors. I'm actually writing both blog posts at the same time, but water was technically started first, so it will be published first. Working on water is pretty fun and a nice break from the more difficult parts of development such as AI navigation and building object placement logic. The theme here is to make water look more realistic, but also add a varying degree of dirt and mess to match with the recent changes to basements. This post is mostly a slideshow of screenshots of water surfaces in various states of cleanliness.

But the water shader isn't the only thing that's new. Now some swimming pools and flooded rooms have fish! Someone actually suggested it a while back. Adding fish to these areas didn't feel very realistic at the time, but I changed my mind because I felt it would be interesting. I'm always looking to add moving elements to these mostly static scenes. Plus the fish near the surface can generate water ripples to improve the realism of the water surface.

Fish are drawn and animated using the same code as the fish I added to fish tanks some months ago. I had to write a new system for their movement logic though since it's more complex. Fish in fish tanks have a rectangular area to swim in and only need to avoid colliding with each other. However, fish in swimming pools have to avoid the pool stairs, sloped floor, and ladder as well. Fish in basements have quite a few objects to avoid, such as walls and doors. And in both cases, fish will run away from the player when you get too close to them.

Indoor Pools

Indoor pools come in a variety of shapes, sizes, water quality, and states of disrepair. These are controlled by randomly chosen constants that vary parameters such as color, light attenuation/scattering, and other shader effects. If anyone is interested, the updated GLSL water shader source code can be found in my GitHub repo here

We have clean pools with blue tinted water like the one below. The majority of pools are clean like this.

Underground swimming pool with fish swimming in the water. This is the original clean look. Oops, I forgot to enable indirect lighting.
 

At the other extreme, we have pools with cloudy, green, algae filled water and dirt all over the walls, ceilings, and floors. They can still have fish in them though, and the poor water quality doesn't harm the player. It only makes things more difficult to see when walking underwater.

An indoor swimming pool full of algae with dirty walls, ceiling, and floor. Would you swim in this? Would you *drink* this?

Some extra long extended basement rooms have fog in them, or maybe some sort of smoke or haze. This isn't really related to swimming pools, but it does give them a creepy feel. You never know what might be lurking in the shadows at the far end of this pool.

Long and narrow basement swimming pool with green water and fish in a dark, dirty, and foggy room.


Flooded Basements

The lower floors of extended basements ("backrooms") sometimes have water in them as well. The water level varies randomly, from a shallow, almost invisible later, to water so deep the lowest floor is completely submerged. Fish live in these flooded levels, though these mazes of rooms can be so large that the fish are hard to find. As with swimming pools, flooded rooms have a range of water quality represented by a random mixture of mud/dirt (brown) and algae (green).

I remember seeing one basement with a shallow layer of cloudy green water on the floor that made it look like a swamp. But I wasn't able to find it again as these colors are somewhat rare, so here's a screenshot of murky green-black water. (I have indirect lighting intentionally disabled here so that it looks darker.)

Dark, flooded basement with medium depth green water full of mud and algae.

Then we have rooms with a very shallow layer of water on the floor. The layer is so thin that it's hard to tell what color the water is, but I'm pretty sure this one has clean water. Ripples look pretty good in shallow water. The walls and floor are dirty though. It looks odd with water stains under the water, so I guess these dark stains are dirt, mold, or something else.

Dirty flooded basement with a thin layer of clear water on the floor and some blue colored lights.

Here's an interesting looking area with a completely flooded lower level and water on the floor of the level above. I like the way the colored lights interact with the water. There's no visible dirt in this basement, though I believe the water is slightly muddy.

A relatively clean basement with an entire flooded level and submerged stairs, with orange lighting.


Outdoor Pools

Next, we move outdoors into the sunlight to view some exterior swimming pools. There are two styles of pool: round above ground, and rectangular in-ground.

I've made two changes to these pools. First, they now have caustic light patterns drawn on underwater surfaces visible to the sun. This is done with a texture decal applied to the surfaces that varies in brightness and color to match the sun color and angle. Shadows are also applied to this layer.

Here's a screenshot of a round above ground pool in someone's back yard. This pool has crystal clear water and the sunlight reaches to the bottom.

Round above ground pool with clean, clear water and caustic light patterns on the inside sides and bottom.

And here's a nice clean rectangular in-ground pool with a sloped bottom. The pool is next to a back yard covered deck/porch. This one is also very clean and blue, just like the pool at my (real life) house currently is. (Yes, it makes for a good reference.)

Square in-ground swimming pool with sloped bottom and caustic patterns visible under the water.

But we can have dirty green pools outdoors as well as indoors. In fact they're probably more common outdoors where the sunlight makes the algae grow. The water is cloudy and opaque, and no light reaches the bottom to produce caustics. In fact, you can't even see the bottom of the pool ladder. The owner of this house really needs to do a better job cleaning and maintaining their pool!

Rectangular in-ground pool with cloudy green water. No caustics are visible in this one. It needs more chlorine.

These back yard pools are often fenced off and unreachable to the player. Sometimes they're accessible through the house if it has both a front and back door like the house in the second screenshot. They're visible through chain link fences, but it's easier to take screenshots using my debug "flight mode".

3 comments:

  1. The basement pools remind me of the pools in Subliminal:
    https://www.subliminalgame.com/
    Would it be possible to make a bottomless pool?

    ReplyDelete
    Replies
    1. One of the inspirations for flooded basements was the game Dreamcore that I watched someone play through. Subliminal is a similar style game, but newer.

      Yes, I can remove the bottom of the pool and extend the sides down to the bottom of the scene. At some point the bottom would be obscured by fog and not visible. I don't know what would happen with the lighting though. It's an interesting idea. I guess if the player fell in they would die?

      Delete
    2. There, I added "bottomless" pools. Well, they're technically not bottomless but ~100 feet deep. The player will drown while falling to the bottom in gameplay mode. But the bottom is almost black and you can't easily tell when you've reached it, you can only see the lighter area above slowly receding. So it's effectively bottomless.

      Delete