4

How do I simulate water droplets realistically falling, gathering, and flowing down a window? For example, see http://www.youtube.com/watch?v=4jaGyv0KRPw. In particular, I want to simulate how smaller droplets merge together to form larger droplets that have enough weight to oppose the surface tension and flow downward, leaving a trail of water.

I'm aware of fluid simulation, but how would it be applied in this situation?

skyuzo
  • 460
  • 3
  • 9

5 Answers5

4

There was a good rain-on-glass simulation in the ATI Toy Shop demo from a few years ago. See the video starting at 1:30; and here are detailed slides on how all the rain effects work.

Nathan Reed
  • 33,657
  • 3
  • 90
  • 114
3

Metaballs in 2D. A great raindrop example (3D) here, while this shows how metaballs look in motion. You can write this as a shader, if you want to use the GPU.

Alternatively, in late 80's / early 90's demos they sometimes just use transparent sprites and move them down the screen irrespective of one another. It doesn't look too bad, but it's not very realistic. However kudos to those guys back in the day for keeping things simple. I think there are some blendmodes on some platforms that do not add to each other's effect, i.e. they will just merge. This would look somewhat better, using the same approach.

Alexandre Desbiens
  • 1,554
  • 1
  • 12
  • 18
Engineer
  • 29,455
  • 4
  • 72
  • 120
  • That seems useful, but how do I simulate the streaks that droplets leave when they flow down, and how do I simulate the droplets merging into larger droplets that have enough mass to resist the surface tension and flow down? – skyuzo Nov 17 '11 at 21:51
  • Streaks are just smaller droplets, aren't they? Just as in real life, the streak is left behind, as erstwhile parts of the original droplet volume. If you need more volume than that, you can have each metaball growing in volume even as it is losing volume to smaller metaballs it is trailing behind itself. Presumably your mass is a function of the current metaball's diameter, and you do conditional logic based on that, to resist merges? Seems straightforward to me. You're not going to know anything for sure until you get stuck into the code. That's a fact of life! – Engineer Nov 17 '11 at 22:28
  • First link is dead. – House Jun 16 '15 at 03:53
3

Unless rain is especially important in your game I'd go with a fairly simple simulation like the one used for MotoGP described here by Shawn Hargreaves:

Jay (the lead artist) and I found one of those sprays like you use for misting plants, and spent some time squirting it on the office window, then examining the resulting droplets from different angles and against different backgrounds. Here's what we learned:

  • Droplets are egg shaped: roughly oval, but wider at the bottom
  • Droplets have no intrinsic color of their own, unless you shine a bright light on them
  • Droplets refract light as it passes through them, so the scene behind them is inverted and distorted
  • Pretty much the entire street outside our office was visible in every droplet (but upside down and mirrored)
  • Although most droplets appeared darker on top and lighter at the bottom, we decided this wasn't an intrinsic property, but just because the sky was bright that day

...

First, we made a droplet texture. We drew the shape of a typical droplet into the alpha channel, and I wrote a function (using the MotoGP equivalent of a content processor) that generated 2D refraction offsets into the red and green channels.

We were already drawing the main 3D scene into a rendertarget, so we could apply postprocessing effects such as motion blur. It was trivial to draw a number of 2D droplet sprites over the top, using a pixel shader that sampled the droplet texture, used its refraction offset to compute texture coordinates into the main scene image, then sampled the scene at this modified location (a similar concept to this XNA Framework sample).

The linked article includes how they overcame performance challenges in order to maintain 60 fps performance.

DMGregory
  • 134,153
  • 22
  • 242
  • 357
Adam
  • 7,346
  • 19
  • 25
0

I found a good paper related to this topic: "Realistic real-time rain rendering" by Rousseau, et. al. They survey several current techniques (with references) and describe a new algorithm and their GPU based implementation

amb
  • 690
  • 3
  • 9
  • Perhaps you could add a link to it for easy access. :) – Richard Marskell - Drackir Nov 17 '11 at 13:57
  • Google turns up a number of hits, including: http://www.cse.iitb.ac.in/graphics/~pisith/references/realistic%20real%20time%20rain%20rendering.pdf – amb Nov 17 '11 at 14:29
  • Sorry, maybe my question was unclear. I'm specifically looking for simulating water sitting on a window due to surface tension and interactions related to surface tension and merging. I've edited my question. – skyuzo Nov 17 '11 at 21:56
0

Just maybe, you already spelled out your solution, it will just be your job to implement it.

Looking at what you've mentioned, you have the following things to implement:

  1. Metaballs in 2D
  2. Estimated mass from size of Metaball
  3. Estimated surface tension (a constant)
  4. Whether F=mg is enough to overcome the surface tension.

This will give you the desired effect; a more advanced implementation may then introduce metaballs which are "left behind" when the source metaball has a non-zero velocity. Then just apply a function that randomly generates impacting raindrops by throwing metaballs at your surface from a specified vector.

As for the performance of this, your on your own :P.

hiddensunset4
  • 2,087
  • 2
  • 17
  • 27