Gerstner Waves in Unreal Engine 5: Build a Moving Ocean With One Material
Gerstner waves give you sharp crests, wide troughs and correct lighting for a fraction of the cost of a simulation. Here's the math, a ready-to-use Custom node, and how to make objects float on the same waves.

Fungaz
Sine waves are the usual first step for animated water, and they always look a little wrong: the crests are as round as the troughs, so the sea looks like a rubber sheet. Real ocean waves have sharp peaks and wide, flat troughs. Gerstner waves give you that shape with nothing more than a few lines of shader math, which is why they've been a staple of real-time water since NVIDIA's GPU Gems chapter on water in 2004.
In this tutorial you'll build an ocean material in Unreal Engine 5 that adds up four Gerstner waves, moves the mesh with World Position Offset, fixes the lighting with correct normals, and finally reads the same waves in C++ so objects can float on them.
- Engine: Unreal Engine 5.x (the steps use the material editor and, for the last part, a C++ project)
- Level: intermediate. You should know how to create a material and connect nodes
- Time: about 30 minutes
[ADD SCREENSHOT OR GIF: the finished ocean in motion]
How Gerstner waves work
A sine wave only moves each point of the surface up and down. A Gerstner wave also moves it sideways, in a circle. Points bunch together near the crest and spread apart in the trough, which makes crests sharp and troughs wide, the same way water particles move in a real deep-water wave.
Each wave has four settings:
- Direction (D): the 2D direction the wave travels in
- Wavelength (L): the distance from one crest to the next, in centimetres (Unreal's unit)
- Steepness (s): from 0 (flat) to 1 (as sharp as it can get before it folds over itself)
- Speed: not a free setting. In deep water, longer waves travel faster, so the speed comes from the wavelength and gravity
For a point at position P on the flat plane, at time t, the wave works out like this:
k = 2π / L wave number
c = √(g / k) speed (deep-water waves), g = 980 cm/s²
f = k · (D · P.xy − c · t) phase
a = s / k amplitude, from the steepness
offset.x = D.x · a · cos(f)
offset.y = D.y · a · cos(f)
offset.z = a · sin(f)
Tying the amplitude to the steepness (a = s / k) is a handy trick from Catlike Coding's waves tutorial: it means one number controls how sharp a wave is, whatever its size. To get a believable sea, you add several waves together with different directions and wavelengths. Keep one rule in mind: the steepness values of all your waves should add up to 1 or less, otherwise crests can loop over themselves and the mesh turns inside out.
Try it: Gerstner waves in your browser
The demo below runs the exact same math as the material you're about to build, starting with the same four waves (in metres instead of centimetres). Switch between Gerstner and Sine to see the crests sharpen, watch the side view to see each point of water move in a circle, and push the total steepness past 1 to see the mesh fold over itself. Turn on Wireframe to see the vertices bunch up at the crests. Open the demo full screen.
Step 1: Make a dense water plane
World Position Offset moves vertices, so the waves can only be as detailed as the mesh. The default plane has four vertices and will not move at all in an interesting way.
- Open Modeling Mode (Shift+5) and choose Create → Plane.
- Set the width and depth to 10000 (100 metres) and the subdivisions to around 200 in each direction. That gives a vertex every 50 cm.
- Click Accept. Unreal saves it as a Static Mesh asset you can reuse.
Your shortest wavelength should cover at least four to six vertices, or it will look jagged. If you need short waves over a large area, use several tiles of this plane: because the waves are calculated in world space, neighbouring tiles line up with no visible seam.
Step 2: Set up the material
- Create a material called M_GerstnerOcean and open it.
- In the Details panel, untick Tangent Space Normal. We'll calculate the normal in world space, and this tells Unreal to expect that.
- Add four Vector Parameter nodes named WaveA, WaveB, WaveC and WaveD. Each one packs a whole wave: R, G = direction X and Y, B = steepness, A = wavelength in cm.
- Add a World Position node and set its World Position Origin Type to Absolute World Position (Excluding Material Shader Offsets). "Excluding" matters: in the pixel shader we want the position of the flat plane, before the waves moved it.
- Connect it to a Truncate LWC node. In UE5, world positions use Large World Coordinates (double precision), and the Custom node we're about to write expects plain floats.
- Add a Time node.
Starting values that look like a calm open sea:
- WaveA: (1, 0, 0.25, 6000)
- WaveB: (0, 1, 0.25, 3100)
- WaveC: (1, 1, 0.15, 1800)
- WaveD: (−0.7, 0.4, 0.1, 900)
The steepness values add up to 0.75, safely under the limit.
Step 3: Write the Gerstner Custom node
You could build this from math nodes, but four waves turn into a wall of spaghetti. A Custom node keeps it readable. Add one and set it up like this:
- Output Type: CMOT Float 3 (this is the wave offset)
- Inputs (in this order): P, T, WaveA, WaveB, WaveC, WaveD
- Additional Outputs: one output named WaveNormal, type CMOT Float 3
Paste this into the Code field:
// Sum of four Gerstner waves.
// Returns the offset for World Position Offset and writes the world-space normal to WaveNormal.
float4 waves[4] = { WaveA, WaveB, WaveC, WaveD };
const float g = 980.0; // gravity in cm/s²
float3 offset = 0;
float3 tangent = float3(1, 0, 0);
float3 binormal = float3(0, 1, 0);
for (int i = 0; i < 4; i++)
{
float2 d = normalize(waves[i].xy);
float steepness = waves[i].z;
float k = 2.0 * PI / max(waves[i].w, 1.0);
float c = sqrt(g / k);
float f = k * (dot(d, P.xy) - c * T);
float a = steepness / k;
float sf = sin(f);
float cf = cos(f);
offset += float3(d.x * a * cf, d.y * a * cf, a * sf);
// Derivatives of the displaced surface, used to build the normal.
tangent += float3(-d.x * d.x * steepness * sf, -d.x * d.y * steepness * sf, d.x * steepness * cf);
binormal += float3(-d.x * d.y * steepness * sf, -d.y * d.y * steepness * sf, d.y * steepness * cf);
}
WaveNormal = normalize(cross(tangent, binormal));
return offset;
The tangent and binormal lines are the slopes of the moved surface along X and Y. Their cross product points straight out of the surface, which is exactly the normal we need. On a flat sea they stay (1, 0, 0) and (0, 1, 0), and the normal points straight up.
Step 4: Connect everything
- Truncate LWC → the Custom node's P input.
- Time → T.
- The four wave parameters → WaveA to WaveD.
- The Custom node's main output → World Position Offset.
- The WaveNormal output → Normal.
- For a quick look, set Base Color to a deep blue (around 0.01, 0.05, 0.08), Roughness to 0.05 and leave Metallic at 0.
Use the main output for World Position Offset, not an additional output. There's a reported issue where a Custom node's additional outputs read as zero when they feed World Position Offset.
Why does this work when the same node feeds both pins? Unreal compiles World Position Offset into the vertex shader and Normal into the pixel shader, so the node runs once per vertex to move it, and once per pixel to light it. Thanks to the "Excluding Material Shader Offsets" setting from Step 2, both runs see the original flat position, so they agree on which part of the wave they're looking at. The per-pixel normal is also smoother than anything the mesh resolution could give you.
Save, drag the plane into a level and apply the material. Press Play or turn on Realtime in the viewport to see it move.
[ADD SCREENSHOT: the finished material graph]
Step 5: Stop the water from disappearing at the edges
Unreal decides whether to draw a mesh using its bounds, and those bounds don't know your material moves the vertices. When the camera looks at a wave that has risen above the plane's original bounds, the whole tile can pop out of view. Select the plane in the level and, under Rendering, raise Bounds Scale to around 1.5–2. That's enough for most seas without hurting culling much.
Step 6: Tune the waves
- Make one long wave the boss. One wave with a long wavelength sets the swell; the others add detail. Wavelengths that are roughly half of each other (6000, 3100, 1800, 900) give a natural mix.
- Avoid exact multiples. If one wavelength is exactly twice another, the pattern repeats visibly. Slightly off values like 3100 instead of 3000 hide the tiling.
- Spread the directions. Aim most waves within about 60° of the wind direction and add one or two off-angle waves to break up straight lines.
- Watch the total steepness. For a storm, raise it towards 0.9 rather than making a single wave steeper.
- Make a Material Instance. Create one from M_GerstnerOcean so you can tweak the four waves live while the game runs.
Step 7 (optional): Make objects float on the same waves
A boat needs to know the water height at its position, and the GPU can't easily tell your gameplay code. The fix is to run the same math on the CPU. There's one catch: Gerstner waves move points sideways, so the point that ends up above a given spot started somewhere else. A few quick guesses find it.
// Same math as the material. Waves are packed like the material parameters:
// X, Y = direction, Z = steepness, W = wavelength in cm.
static FVector GerstnerOffset(const FVector2D& P, double Time, const TArray<FVector4>& Waves)
{
constexpr double Gravity = 980.0; // cm/s²
FVector Offset = FVector::ZeroVector;
for (const FVector4& W : Waves)
{
const FVector2D D = FVector2D(W.X, W.Y).GetSafeNormal();
const double K = 2.0 * PI / FMath::Max(W.W, 1.0);
const double C = FMath::Sqrt(Gravity / K);
const double F = K * (FVector2D::DotProduct(D, P) - C * Time);
const double A = W.Z / K;
Offset.X += D.X * A * FMath::Cos(F);
Offset.Y += D.Y * A * FMath::Cos(F);
Offset.Z += A * FMath::Sin(F);
}
return Offset;
}
// Water height at a world XY. Finds the point of the flat plane that the waves moved to this XY.
static double GetWaterHeight(const FVector2D& XY, double Time, const TArray<FVector4>& Waves, double WaterBaseZ)
{
FVector2D Source = XY;
for (int32 Step = 0; Step < 4; ++Step)
{
const FVector O = GerstnerOffset(Source, Time, Waves);
Source = XY - FVector2D(O.X, O.Y);
}
return WaterBaseZ + GerstnerOffset(Source, Time, Waves).Z;
}
WaterBaseZ is the Z position of your water plane. For a simple boat, sample the height at three or four points around the hull every tick and push each point up with a force when it's below the water. That gives you bobbing and tilting for free.
Keep the clocks in sync. The material's Time node and GetWorld()->GetTimeSeconds() both follow game time, so they normally match. For full control (pausing the sea, speeding it up, or networking it), create a Material Parameter Collection with a scalar called WaveTime, set it from your code every tick, and use it in the material instead of the Time node. Pass the same four wave values to both sides too, for example from a Data Asset that also sets the material instance parameters.
Troubleshooting
- Nothing moves: the mesh doesn't have enough vertices, or the viewport isn't in Realtime mode.
- Spiky, inside-out crests: the steepness values add up to more than 1. Lower them.
- Lighting looks flat or inverted: Tangent Space Normal is still ticked in the material details.
- Waves look jagged: the shortest wavelength is too short for the mesh. Raise it or subdivide the plane more.
- The water vanishes from some angles: raise Bounds Scale (Step 5).
- Tiles don't line up: the World Position node is set to a local or camera-relative origin type instead of Absolute World Position.
- Compile error about types on the P input: the Truncate LWC node is missing between World Position and the Custom node.
Where to go next
- Better shading: add a Fresnel-driven colour change, a normal map panning in two directions for small ripples, and depth fade where the water meets the shore.
- Foam on the crests: where the waves bunch up most, the tangent and binormal shrink. Their lengths make a good mask for white foam on the peaks.
- More waves: raise the array size and add parameters. Eight to twelve waves still cost very little.
- Unreal's Water plugin: if you want rivers, lakes, shorelines and built-in buoyancy, Unreal's Water system also uses Gerstner waves under the hood. Building your own first is still the best way to understand and control what it does.
Further reading: GPU Gems, Chapter 1: Effective Water Simulation from Physical Models by Mark Finch, and Catlike Coding's Waves tutorial by Jasper Flick, which covers the same math step by step in Unity.

How Open-World Games Handle Thousands of Objects
Ondas de Gerstner na Unreal Engine 5: crie um oceano em movimento com um único material
No comments yet — be the first.