"The most realistic sailing simulator ever made"
 
Become a pioneer !!
Stay informed
Access beta versions
Subscribe

In depth: Simulating waves

Posted on June 22th, 2016 by Richard Knol

In the sailaway simulator the wave height and wave length are currently only dependent on the overall depth of the water and the amount of wind in the past 48 hours and this needs to change.

The waves in Sailaway are computed inside the shader and run on the graphics card, because this is much faster than doing it on the CPU. So in order to make the wave depend on the depth of the water, we need to tell this shader where the shallow and deep areas are. The easiest way to pass a grid of depth values to a shader is by using a texture. In this case a Depth Map.

In the picture below you can see the ocean mesh (5,000 meter extents) and the terrain (radius of 10,000 meters). Due to a logarithmic scale the terrain you see has a real world radius of 50,000 meters.
As you can see, the terrain is much bigger than the ocean. In a westerly wind, the island on the left would have an effect on the waves between the 2 islands. But if we only sample the ocean depths underneath the sea mesh, the island would be overlooked entirely. This means that the depth map needs to be about 2 x bigger than the ocean itself.

A depth map of 1K x 1K pixels would result in tiles of 20 x 20 meters when projected onto the sea mesh. This is small enough for our purpose, but calculating 1 million depth samples would take way too much time. And these calculations would have to be done on the CPU. To overcome this problem we plan to use a depth map of only 64 x 64 pixels and use a logarithmic scale to divide the tiles over the sea mesh.

We need to tell the waves in one spot that they need to be lower because upwind there is a shallow area which affects them. The plan is to postprocess the depth map after the depths have been set in the pixel values. This process would move through the pixels from left to right or whichever way the waves travel and then affect the next pixels with the values of the previous ones. We could even do this in 2 additional directions +20 and -20 degrees to simulate the effect of waves curving around an island. I can tell you in a few days if this idea works.

Waves become shorter in shallow water. But if we make them shorter, they don't match the pattern of the adjacent waves in a deeper part of the sea anymore and we get ugly artifacts where they meet. To be honest, we haven't solved this problem yet and we'll see how it goes.

A bit of background info: The waves in Sailaway are made up of 6 independent sine waves that travel in slightly different directions and have different heights, lengths and speeds. When you let these sine curves interfere with each other a realistic wave patterns emerges. To make the waves more real, we make the from of them steeper and the back of the wave less steep by pulling the top forward.

The downside of this approach is that the waves originate in an imaginary, distant location and travel towards the camera over time. But when the wave direction changes or the wave length changes or the wave speed changes, they are recomputed from that imaginary location towards the camera and you will see them jump from one position to another. Yuck. We need to change that drastically. The origin point of the waves always needs to be the position of the camera or the boat so that when the waves changes they change always takes place around this visible center, which makes the change gradually instead of jumpy. But this is much harder that it seems and requires some serious calculation, because this new origin (the boat or the camera) moves, while the waves should appear to be unaffected by this movement.


Curious? Want to know more? Subscribe and gain access to early releases and stay informed.
Previous article Next article