For a pirate-themed game it was necessary to create ocean waves that not only look realistic but also physically interact with floating objects like boats. Just as the ocean is infinitely vast, so should it be in the game: A distance based tile rendering mechanism had to be implemented.
The first attempt to simulate ocean waves involved using a plane as an object and applying a shader to it. This allowed the waves to be visually represented, but physical objects could not interact with them.
In the second attempt, the nodes of the plane were moved in the code rather than visually manipulated by a shader. This enabled physical objects to interact with the plane, but performance dropped rapidly even with a small number of nodes.
A combination of both solutions was required: The positions of the nodes were calculated and moved within a shader. The key idea was to replicate these calculations in the code, allowing physical objects to query the water height at a specific point without needing to compute every individual node.
The Addition of multiple sine waves defines the height of the ocean at any given point. If you look at the surface of ocean-waves you will notice that particles on the waves not only move in height but also move back and forth. This behaviour can be simulated by using so called Gerstner waves.
Unitys shader graph is used to create the visual appearance of the waves. The height of a specific point defines its color and transparency. Looking through water a distorted
Together we find asolutionto your problem.
solution