Jump to content
  • Advertisement
Sign in to follow this  
ZealousEngine

Rain... seeking a elegant solution involving shaders

This topic is 4550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive been toying with different implementations for some time now, and cant commit to any one method. I have a fast particle system, but it just seems like there has to be a 'better' way to do rain/snow. Ive seen some papers on 'scrolling texture' style systems (see link) and it got me thinking, maybe particles arent the only game in town. Perhaps you could combine particles, scrolling textures, and shaders to create some nice looking weather. So, what are you guys and gals using for your weather system? Thanks in advance for any info! - Heres that article, its pretty neat, although I can only see it working in a flight sim (where the camera is never up close to a object). http://www.ofb.net/~eggplant/rainsnow/rainsnow-sketch.pdf

Share this post


Link to post
Share on other sites
Advertisement
My rain/snow is a simple extension to my particle system... this allows rain to properly bump on terrain and vehicles etc....
I simply create rain where the camera is, and expand the "spawnpoint" to compensate for motion etc.

Slightly overkill to treat each particle individually, but unless you need REALLY heavy rain this works fine. :)

Also, snow that builds up the longer it snows is quite cool ;D

Edit:

Sound adds a large factor to the whole rain experience too. :)
And the amount of rain particles can be adjusted, for lower end computers...

Share this post


Link to post
Share on other sites
Hello,

I remember some guy at MS games saying he used 4 sliding texture planes for a flight simulator. It works great in the distance since the large area of the sky fools the eye to not see they are texture layers. You could use something like that for the background or distance. Since you said it will get close to objects, you could use shaders to blend rain layers of bigger droplets so it appears on the front of the camera. You could also take use of your particle system to make fall small blocks of rain texture. There are many solutions and I'd suggest you try out some tech demos to test them and choose which one best suits your needs. Hope this helps,

JVFF

Share this post


Link to post
Share on other sites
To create a realistic rain effect, you have to take into consideration the many visual cues that rain creates in real life:

- The rain drops themselves
- Small rain splashes where rain hits the floor and other surfaces
- Wet surfaces (high specularity with subtle reflections off certain surfaces)
- Puddles
- Rain streaks down window panes (and the distortion these streaks create)
- Streams of water created by the rain (flows of water off the sides of buildings for example)
- The sky (dark gloomy clouds)

Just take a look at the ATI Toy Shop Demo for an example (hopefully, ATI will release some slides soon - I know they have lectured about the technology behind the demo). Here are some ideas to add further inspiration to your weather:

For the rain drops themselves it is usually infeasible to use a particle system (what with all of the other calculations going on), so many games use a screen-space effect (just like the scrolling texture method that you mentioned). You could combine such an effect with a refraction (or distortion) technique similar to the steam in Far Cry or the exadurated windows in Doom 3. You can find out more about this distortion effect in the GPU Gems 2 book - there is an article called "Generic Refraction Simulation".

When the rain hits the ground and creates a splash, it is computationally infeasible (nigh on impossible if you are using the screen space technique) to calculate the exact position of the collision and generate a splash (either a small animated mesh or a billboard). If you have lots of rain, you can just get away with creating random splashes. You have to be careful here - you don't want to create splashes on walls or indoor areas!

A huge visual cue that would make your rainy scene believable would be to get your outdoor surfaces really looking wet. This could be done with specular lighting - if you are using some form of normal mapping then you could do the specular lighting per pixel in a shader. You could also add subtle reflections to these surfaces.

To enhance the effect, you could use a particle system to add extra detail to specific areas in your scene. On a really rainy day, you would get small streams off water off sides of buildings and gutters.

Streaks down window panes created by rain (and distortion caused by these streaks)and realistic looking puddles would be the icing on the cake!

Share this post


Link to post
Share on other sites
Ive seen the toyshop demo, it is nice. So youre saying what I thoguht all allong, that is you cant (well, shouldnt) use a particle system for such heavy rain, and instead should use some kind of billboard/scrolling teqhnique. But how do you solve the problems I talked about with such a system?

For example, lets say I implement rain like suggested in that article I posted. What happens when youre looking at a object up close? The effect will cause an error that makes it seem like there is a large distance between you and something thats right infront of your face.

Share this post


Link to post
Share on other sites
How about rendering the objects in your scene that are close to the camera to a texture and using this texture as a mask for regions where the raindrops shouldn't be visible? Basically it comes down to rendering an 'occlusion map' for a specific depth and using that to clip the rain.

It's just a quick idea, but if you are using a screen-sized quad to overlay the rain on the scene it might just work out. You could use a shader to do the masking operation and you can use a custom z-compare function on the render-to-texture pass to only get the polygons up to a limited depth from the camera.

To speed things up, you can render to a low-res texture and stretch that over the screen. Any magnification artifacts would only make the effect look better, since it would make it look like the raindrops actually hit the closer objects instead of just their silhouettes (sp?).

Hope this helps (and makes sense :)

Share this post


Link to post
Share on other sites
This is just an idea but:
couldn't you have a rain texture with depth encoded into it for each drop? Then just overlay this texture as a full screen quad, writing the stored depth values to gl_FragDepth. This would clip against already drawn objects wouldn't it?

Share this post


Link to post
Share on other sites
Writing to depth in a fragment shader breaks the some of the early z-buffer rejections that most cards have these days, which makes it slower in that sense, and my understanding is that it will only affect the particular pass you are doing it on. My suggestion is to try it and see if it is too slow for your needs.

-Mezz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!