In this lesson, you will learn how to transition from simple vertical vertex displacement to the realistic, rolling motion of water using Gerstner Equations.
Beyond Simple Sine Waves
While basic vertical displacement moves vertices up and down like a piston, water molecules in nature move in circular orbits. The Gerstner equation simulates this by displacing vertices both vertically and horizontally. As a wave crests, the horizontal displacement pulls vertices toward the peak, creating those characteristic sharp, narrow crests and broad, flat troughs seen in realistic oceans.
The Mathematical Core
To implement this in Shader Graph, you need to apply two simultaneous offsets to your vertex position based on the wave’s Amplitude, Wavelength, and Direction.
For a single Gerstner wave, the position is calculated as:
- Horizontal Offset ( and ):
Amplitude * Direction * sin(dot(Direction, WorldPosition) * Frequency + (Time * Speed)) - Vertical Offset ():
Amplitude * cos(dot(Direction, WorldPosition) * Frequency + (Time * Speed))
Implementation Strategy
In Shader Graph, you will construct a Custom Function Node or a series of math nodes to handle these offsets.
- Define Inputs: Create properties for
Wave Speed,Steepness, andDirection. - Calculate Phase: Use the
Timenode multiplied bySpeedadded to theWorld Positiondot product with yourDirectionvector. - Apply Displacement: Connect the Sine output to your horizontal axes (
XandZ) and the Cosine output to your vertical axis (Y). - Vertex Stage: Ensure your master node is set to Vertex Position output. Because this modifies geometry directly, make sure your mesh has enough subdivisions; a simple flat plane won't show the rolling displacement if it lacks the necessary vertex density.
By offsetting the horizontal position, you stop the wave from looking like a rhythmic pulse and start seeing the "rolling" motion that defines fluid movement. To get that iconic look, you can sum multiple Gerstner wave nodes together with varying directions and frequencies to create complex, chaotic interference patterns.
Key Takeaway: Gerstner equations produce realistic water movement by coupling vertical elevation with horizontal vertex displacement, creating the sharp, circular-orbit motion of natural waves.