URP Water Rendering
1.4 K
I wanted to implement a versatile water rendering solution integrated directly with the Universal Render Pipeline (formerly the Lightweight Render Pipeline) in Unity 2019
The tide is implemented with standard Gerstner waves in a vertex shader, utilizing hardware tessellation to dynamically increase detail closer to the camera.
The water scattering is implemented using a simple Beer's Law color absorption model and user-configurable scattering coefficients. A simple hack modifies the scattering terms as the normal and viewing angle points towards the horizon, providing a relatively convincing "glow-through" effect that mimics subsurface scattering.
Specular reflections utilize the URP's provided shader library for PBR lighting functions. Other reflections are implemented with a simple planar reflection script ported from Unity's own Boat Attack tech demo. Refractions are performed by simply perturbing the UV offset for the opaque texture read.
One layer of pure depth-based foam was used at first, but I found this to look strange at the edges of objects, so I also implemented a simple system that rendered sea foam opacity into a render texture. Each frame, the foam in the render texture is pushed around with the same Gerstner wave parameters as the water's vertex shader and is additionally blurred across neighboring pixels and faded towards zero over time, and then new foam is injected in from both wave peaks as well as objects with a simple foam injection script attached. This allows foam to sit persistently on the surface of the water, slowly fading out over time.
Allie Stagner