Breakdown 3 of 3

Making the ocean's details

I made the ocean look stylised and easily customisable with foam, caustics and wet sand.

Making the water look convincing

The first version of the ocean used a single tiling normal set and was particularly interesting. Following Marier’s article on water shaders (Marier, 2022), I moved the surface to Single Layer Water for proper scattering and absorption, then added fresnel-based reflection and roughness, refraction and pixel depth offset. Near and far 4-way panner chaos normal maps then broke up the reflections at both distances and did more to hide the tiling than anything else.

Foam and dithering

The foam comes from three sources:

  • Distance fields - It reads the mesh distance fields Unreal already generates for Lumen, so anything placed in the water gets foam around it for no performance cost.
  • Depth - It uses the difference between the water’s depth and the scene behind it to find shallow areas.
  • Wave crests - It is driven by the mask the Gerstner node outputs, so it moves with the waves and highlights high points.

These are brought together in a single mask, which then drives a foam texture. The masks also use noise to help break up the edges. To avoid a hard edge where the water meets a very shallow area, the shader uses DitherTemporalAA into pixel depth offset to fade the foam out much more gently without needing real translucency, which would be more expensive.

A curved sandy shoreline at golden hour, with a soft band of pale foam along the water's edge fading out into the sea
The shoreline foam fading out into the water.

Caustics

The caustics aren’t part of the water material. They’re a separate world-space decal material, placed as a decal volume over the seabed and based on Ben Cloward’s water caustics tutorial (Cloward, 2020).

The caustics decal material graph in Unreal: absolute world position and the scene's world normal feed a projection, two panned caustic textures are distorted and added, then multiplied by a strength parameter into base colour and opacity
The caustics decal material.

It projects from absolute world position rather than UVs, and uses the scene’s world normal to wrap to slopes even though it’s a top-down projection. Two caustic textures pan at different speeds and scales, both warped by a panning distortion texture, and are added together so the pattern never settles into an obvious loop.

The sum goes into base colour, scaled by a strength parameter, and also drives the decal’s opacity. The caustics started out emissive, which looked fine at midday but glowed through the water at sunset. In base colour they react to the scene’s lighting like everything else.

Sand under shallow water, covered in thin, wavy bright caustic lines with faint colour fringes, wrapping over the slope of the dune
Caustics on the sand. Subtle is better.

Wet sand

The wet sand is done in the landscape material, not the water. Below a set height, a sine of time moves a wet band up and down between a minimum and a maximum, so the waterline creeps in and out. Inside that band the base colour darkens and the roughness drops, making the sand darker and shinier at the same time, the way it gets when a wave pulls back over it.

Overhead over the shallows. The wet band on the sand follows the waterline in and out.

Sources