Inspired by this post, I decided to try my own hand at creating a simulated ocean with Gerstner waves. After a few months of work, I managed to complete it with the help of colleagues, with the goal of releasing this publicly for anyone to use this in their games or to simply learn how it works.
Features:
- Multithreaded (honestly have no idea if this is working properly)
- Frustum culling
- Vertex Lerping (distant vertices aren’t updated every frame)
- Customizable settings (ocean size, detail, color, etc…)
- ‘Infinite’ (the ocean plane will follow your camera)
- Vertex coloring / depth coloring
- Texture scrolling
- Accurate & performant height lookups → Buoyancy system for boats included
- Zone system, allowing you to create custom zone areas with different wave parameters (ex. rough sea areas)
- Whirlpools
- Ocean plane can be subdivided to have more vertex detail near the camera
- Shorelines (vertices are slightly transparent and colored differently near shallow water)
- Synced between the server and client (can do precise height lookups on the server/client)
There are definitely improvements that can be made to the ocean, which are mentioned in the main script.
Additionally, this isn’t a perfect system, and comes with some limitations due to performance or technical reasons:
Limitations:
- Height Lookup: It can rarely ‘fail’ at certain times if the vertices of the ocean mesh are very deformed, an example being a whirlpool, since the vertices are displaced in it. There are some precautions to avoid this from happening.
- Ocean texture near whirlpools: The UV’s of the ocean are rotated near a whirlpool in order to mimic a vortex effect, and this obviously leads to distortion / warping around the whirlpool due to the rotating texture.
- Vertex popping: Because of the way the LOD for the ocean works, vertices can occasionally ‘pop’ when the ocean plane readjusts itself to follow the camera, depending on your wave parameters. This is specifically due to the LOD having no smooth transition between different levels.
There are also some issues with EditableMeshes in general, such as vertex transparency not functioning properly unless the entire mesh plane is slightly transparent, alongside some frustum culling issues Due to this, some features may not work correctly until these issues are fixed.
Videos:
Accessing the place:
You can access the ocean system here: Ocean Simulation - Roblox
There are two scripts inside StarterPlayerScripts for running the ocean, as well as multiple ModuleScripts in ReplicatedStorage. For editing the way the ocean looks, there’s a ‘Settings’ module where multiple properties of the ocean can be modified to suit your needs.
Additionally, there’s a boat, whirlpool, and rough sea area with scripts inside them to show how they’re set up.
Comments are also placed throughout most scripts / modules to help give an understanding of how it works.
How to use:
- Main script is located in StarterPlayerScripts
- Modules are in ReplicatedStorage (‘Gerstner’ module has a settings module nested inside)
- 2 boats are under Workspace, one is a boat with buoyancy simulated on the server and one is a controllable boat simulated on the client
- A whirlpool and rough sea area are included to demonstrate how they are spawned in
- A single part with buoyancy is also included to demonstrate height lookups for a single point / part
- Workspace.Ocean is a folder where the ocean plane(s) are stored
- Workspace.Map is a folder for islands required for shorelines to function
