Two Times Pi
Description:
Against the Tide is a technical demo for a strategy simulation game, developed in Unity. The concept of the game is that it is a colony sim, but your objective as a player is to restore a coral reef. It features a grid system, where each cell of the grid has environmental properties that affect coral growth (temperature, acidity etc.) and the player can place buildings on the grid that affect those properties and therefore the coral growth. The player is rewarded for successful reef restoration, allowing them to unlock more building types.


The water shader in Against the Tide uses a simplified version of the Gerstner Wave function to displace the vertices of the water surface plane. It combines together a number of the same wave functions to create a more dynamic and natural look than a single wave. I looked at Fast Fourier transform but for the stylized appearance I was wanted, this simpler method was totally sufficient.
​
The game features buildings that can float on the ocean surface. To create the appearance of the buildings floating I replicated the same code used to produce the waves in the shader in a c# script. In this way, I could "sample" the wave displacement at a given world space coordinates and calulate the height of the water at that point.
Below is the WaveManager script that references the properties of the water shader and replicates the wave function:


x
And below is the Floating Object class that makes use of the Wave Manager's GetWaterHeight method. It uses an array of "floating points" (transforms) assigned in the inspector to determine where the object interacts with the water. I could capture the water height at each of these points but I was happy with just using the main transform position of the game object at start to establish where I should sample the water height. This method is not designed for moving floating objects but it could be easily adapted to do so.
For each floating point below the water surface, an upwards force is applied proportional to its depth below the surface.


x
