3089’s Weather System

Hey all,

I spent quite a bit of time working on the weather system for 3089 & I thought I’d share how I implemented it. I had two goals: it must look good and it must be fast. I didn’t want 3089 to start lagging when the rain kicked in, even on lower-end machines, and I believe I accomplished that. On how it looks, take a look at this video (I know I already posted it, but it also is useful for this post!):

The first thing I discovered, is that rain can be accomplished by only being a camera effect. You don’t need to worry about rain in areas you are not looking at or cannot see. So, I just needed to figure out how to display falling rain infront of the player that is exposed to the sky.

The conventional method for implementing rain seemed to be with a particle system above the player’s head. The particle system would have needed to be rather large, since the player in 3089 is quick & we wouldn’t want the player outrunning falling rain particles. Another problem with a particle system is the resources required to handle it… each rain drop would need to be performing collision detection for roofs and trees. Particles would also need to be dropped behind you (since the player could quickly turn around and expect to see rain).

I decided to go with animated billboards. Basically, flat “quads” that will always point towards the player & be textured with falling rain. However, making this system look good & run fast took quite a bit of work. My terrain & buildings are all physics objects & collision detection is handled by the native bullet library that comes with jMonkeyEngine. Therefore, the original plan was to perform a bunch of physics ray tests, from the sky to the ground, infront of the camera to determine where to place the animated billboards of rain. Unfortunately, performing a ray test every frame for every spot infront of the player would require too much processing power than I was comfortable with. I could increase the width of each animated billboard to reduce the resolution of physics ray tests required, but that would too quickly make the rain look worse near edges.

To solve these problems, I did a few things. First, I made all columns of rain snap to a grid. Therefore, if a physics ray test was run on a spot infront of the player, another physics ray test would not need to be done near that area again (it also helps that the terrain doesn’t change, so that previous ray test will remain accurate). Secondly, if a column of rain is being rendered at a certain spot, I don’t need to worry about calculating rain behind that spot — since the closest rain column will obscure more distance rain effects anyway. To implement this system, I first calculate the angle the player is looking in. I then perform a sweep, from left to right, from about -45 degrees to +45 degrees from the player’s direction. For every grid point forward from the current direction being calculated, I perform a ray test from the sky to the ground. If a ray test shows that point is exposed to the sky, I place a rain column and move on to the next angle in the sweeping procedure. If I already had a rain column for that grid-snapped point, I would skip the ray test and also move on to the next angle in the sweeping procedure. Finally, I only do this procedure every tenth of a second instead of every frame.

To handle the falling rain effect, I started by drawing a 32×32 image of falling rain drops. I wrote a custom OpenGL shader that takes in the texture coordinates of the flat column and adds the current time to the vertical component. As time passes, the rain drops! I also added in some code in the shader to make the rain fade (by increasing the alpha) based on the distance from the camera.

This system works pretty good when the player is looking forward, but what happens when the player looks directly up or down? When the player looks up or down, rain needs to be falling around you in all directions. To solve this, I simply determine when the player looks up (or down) enough & modify the sweep procedure to do a full 360 degree scan around the player.

I’m sure there are better rain systems (and I may implement them if I find them!), but I am happy with how this system is working so far. I hope this helped some other developers out there determine how they will implement rain in their 3D games!

– Phr00t

Advertisements

17 responses to “3089’s Weather System

  1. Hi Phroot!
    Very interesting blog post! Please write more “developer stuff”!

    One thing i am angry about is your demo limitation for this game.
    I bought 3079 and Gentrieve 2. There are fun games and i enyoued them!!!
    Well done! But the demo limitation for 3089 are ridiculous in my opinion.

    -> All “special” items, like the grappling hook, telelocator & timewarp, are disabled.
    Wtf i can only try for 10 minutes and i am not allowed to use the most fun parts of your game?!

    Please think about it.

    • I do plan on writing more developer stuff.. takes a bit of time though and I need to budget it wisely!

      About the demo limitations… if I let people use the most fun parts of the game & play longer, then there wouldn’t be much incentive to buy the full version, right? 🙂 The goal of the demo is not to provide a rich & complete gaming experience, it is only suppose to determine if you want to play more (and see if the game runs on your machine etc.). I work very hard on these games & I don’t want to give away too much of my hard work away for free… I rely on income from these games :-/

      If you want to play the most fun parts, you’ll have to compensate me for putting all that work into implementing those fun parts. I believe that is fair.

      Thank you for supporting me with 3079 & Gentrieve 2, I’m glad you enjoyed them!

      • You are right! Your points are all valid.

        10 minutes are okay but the actions you can do in this timeframe are to limited! But i think new players (i mean the player that never played your other games) might be discouraged. They spawn in the unknown new world. Discover a house. Discover a sale block … You can buy a grappling hook, but you can not use it. You’re looking for a weapon … You do not find … oh nice landscape… i can jump… what can i do …. Time’s up … 😉

        I do not think this experience attracts new players.

        In the 10 minutes, you should be able to use what you can see / get. That would be fair.

        Thanks for making such games! I had a blast with the last ones!

      • The thing with the 10 limit, though, is it is only “per play”… you can immediately start another game to get another 10 minutes.. then 10 minutes after that etc.

        I changed the wording on my “Demo” page to say “I strongly recommend you play multiple times”

  2. Feedback:

    Rain: when I first saw the rain in a previous build I immediately liked it.. so whatever you’ve done is fine with me. Don’t worry too much about making the rain better than it is for now.. it’s great right now and acceptable.

    Beams: Really like the fact that the beams emit light and you can see the ambient light on the player’s weapon and the surrounding buildings. I don’t like that the beam is completely opaque though and would prefer it to be more transparent and maybe have a bit of plasma-like texture to it rather than being a solid colour.

  3. Yeah about the demo time. I think at least a house with all the shops and stuff when you land so you dont nedd to use the whole demo on finding a weapon.

    • Buildings should spawn close to the player with the necessary shops. Use the map, which is explained in an opening dialog, to help find those shops. You shouldn’t need the whole demo time to do this…

  4. Just curious if there is some way to get: a radiation suit and secondly, an underwater suit.. or whether they’re needed at all? Maybe I am just too much of a noob to know 🙂

      • Oh also (again).. I’m not sure what you’ve done.. maybe it is me getting better.. but even without the homing rifle I am doing a lot better now.. I loaded up the wrong save by mistake and on to one I had difficulty with before but now it’s no problem…. haha..

        One thing that would be really awesome is if you could add a hotkey for for energy and health consumables.. one for each one.. going into the menu mid-combat isn’t the best thing in the world 🙂

      • Going into the menu mid-combat isn’t the best thing in the world because I don’t want people using consumables mid-combat 😉 If I had a hotkey, player’s could spam it & it would make battles unbalanced. Requiring players to go into the menu is a small price to pay to actually use them… I want people to prefer using consumables after a battle.

      • The “Chips” station.. it looks like a computer chip & you will find them using the map when hovering over buildings.

    • They shouldn’t be needed… I balanced out the radiation area to hurt health but give extra energy, so I like that effect & don’t want players to be able to negate it. No underwater suit should be needed… since you are a robot, you don’t need to breathe… you just float around 🙂

      • Oh right.. I must have come across a radiated underwater area in an earlier build and that’s why I avoid staying under water these days.. 🙂

        I can’t remember the level I am now.. but doing much better..

        So the Chip “Workbench” is the same as the place you buy the chips from?

      • Glad you are doing much better 🙂

        Yes, the chips “workbench” is the same one you buy from!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s