Ocean Shader & Buoyancy Physics

For this project, I challenged myself to do build a water shader that used vertex offset in such a way that I could use that offset to simulate things that relied on the surface of the water, like buoyancy.  As such, all vertex calculations are done on the CPU and cross-applied to the buoyancy system, while the shading on the surface of the water is handled separately in a GPU shader.  

I used this article regarding the water physics implementation in Just Cause 3 as my basis for getting started.  

The calculation is an accurate approximation of Archimedes' Principle and physically-based buoyant forces.  As such, the simulation will differ based on the ratio of mass to surface area in the buoyant objects, and it's all calculated in realtime. 

I also built a custom editor for the script which exposes some useful debug options such as previewing the wave normals being used for buoyancy, but more importantly it allows the previewing of CPU waves at runtime with a simple on-off switch to help tune values.

 

As for the shader, it's mostly hand-written, with the basic structure coming from a node-based editor early on in the process (ShaderForge).  It consists of a scrolling normal map, foam, SSS approximation, reflection, refraction, and dynamic phong tesselation, where it adds additional polygons at the peaks of waves for a slightly sharper look.   

I'm making this entire project available below, so if you want to poke around the source code and see what's going on, you are more than welcome to do so!  

Additionally, I've documented the system and how to get started with it, so feel free to check that out as well!

Unity Package

Documentation

Note:  If you're looking for my older water-shader (the one made entirely in ShaderForge from a couple years back), you can find it here.  

© 2017 by Evan Edwards

  • LinkedIn Social Icon
  • Twitter Classic
  • Facebook Classic