We implemented rain by the use of a particle system and a new scrolling normals texture map for the water surface. We started out by generating 100000 particles over the entire water surface at a certain minimum height. The particles accelerate downwards towards the surface when they reach y-position 0 the velocity is reset to 0 and the position randomly reset. Upon impact the raindrops should of course generate ripples on the water surface. It seemed unlikely that we would be able to handle so many epicenters. Firstly the wave equation is rather costly, but this could have been circumvented by limiting the affecting area of each ripple. However because the ripples are very small we would need a very high resolution mesh plane to be able produce said ripples, as per the Nyquist frequency. Instead we decided to find a scrolling normals texture map that would give the impression of ripples. The sudden change in the water surface, meant that we had to tweak the rainfall so that minimum height for raindrop generation is at surface level.
The first attempts yielded an acceptable framerate, but only when there were no balls or waves in the water. To accommodate this we reduced the amount of particles to 50000, however the rain became significantly less intense. This was then further improved by limiting the area of rainfall, at a certain distance the individual raindrops are too small to spot anyway. We reduced the area to a 1000x1000 area around the camera, ¼ of the previous area. The camera position is taken into account when the drops a reset. This allowed us to reduce from 50000 to 30000 raindrops, yielding a much better frame rate and more intense rainfall.
Because the rain keeps falling straight down, the camera can actually outrun the rain if it moves fast enough, but we don’t see that as a problem,since one can actually do the same in real life. A very curious bug has however been observed. For certain camera movements the particle system becomes invisible, we have not been able to isolate the specific conditions.
We have also improved the camera controls and feature which locks the camera to the mouse cursor when pressing the L-key.
This is the last blog post in this project. One could spend a lifetime trying to perfect water simulation. It has been a great learning experience and even though there is a lot of improvements that could be done, we are happy with the results of this project. We feel that we’ve come quite far, especially since none of us had any prior experience in graphics programming and we are very excited to explore the potential of computer graphics in a web browser. This project might be over, but we are all excited to get started on new graphics project, this is just a taste of what’s to come.
//Calle, Emil & Kevin
Link to live demo: