Back To Portfolio

Shallow Water Simulation

Duration: 2 Weeks
Language: C++

I programmed a shallow water simulation based on the Navier-Stokes fluid flow equation for incompressible liquids. The propogation is handled as a "velocity" component of the water that is carried along with the motion of the water, which naturally lent itself to using Verlet integration.

Notable Experiences

  • Integrated the wave propogation using Velocity Verlet integration and compared the integration scheme with Midpoint integration.
  • Developed a minor toolset into the simulation to debug properties like scale, velocity, and meshing.
  • Procedurally generated the water mesh based on the simulation complexity and scale.


The biggest, most frustrating part of working on this project was the disconnect between my physics structures and my rendering structures. Initially, they closely resembled one another and I could basically just swap them over straight away. Once I expanded into 2D, I needed to make the rendering system more robust even though the physics system could already handle the extra complexity. I quickly found that managing all of the vertices, normals, and faces was mind-boggling! What made it worse was my intense desire to remove the ugly "border strips" that happened due to reflecting velocities on the edges. Essentially, I added some invisible cells to the grid and used those as the borders instead, making all the rendered faces based on inner cells. This meant adding one element before and after everything else in both dimensions, and it took me quite a while to realize that I also needed another element added after for the simulation to work in the first place. The worst part of all this is that the code is practically non-maintainable by anyone but me now...
If only all the rendering could be as simple as you, 1D-strip of water...

Another issue that mucked up the works for a long time was the amount of minute details that have went into every aspect of the simulation. Each part of the physics update needs to operate on its own slice of the data, and understanding which goes for what didn't come easily. This also extended to the rendering component somewhat, but the most chaffing was definitely physics. Luckily my parameters were never problematic, so once I solved an issue I knew it was gone.
The opportunity-to-break aspect to this project is very high.

When I was finishing up the project, I thought it lacked flair. While washing around and splashing a bit is very exciting, doing it in boring old blue ruins the fun.
So I added different "color maps"! The regular blue is still around, but if you want to visualize your wave data you can do so in three cool ways:
  1. Ranging from red to blue based on (absolute) height
  2. Attaching a color to each axis based on normals
  3. Coloring the velocities! (I can't remember how I organized this one)
Not only can you see more beautiful colors, it can also help show what's actually going on in the simulation!
I'm probably prouder of these colors than I should be.
Back To Portfolio