Table of Contents

Water module

View this file on GitHub

Short description: An ocean for URP 17: an FFT sea in world metres that hands over to breakers of its own at the coast, shaded as water rather than as a tinted plane, and honest about what the render pipeline will and will not give it.

Everything here works in metres — one Unity unit is one metre in FishMMO, and that is not a convention this plugin can ignore. Deep-water waves travel at √(g/k), so a 64 m swell moves at 10 m/s and a 4 m chop at 2.5 m/s, and the long waves visibly overtake the short ones. At any other scale the dispersion is wrong and the sea moves like a bath.

Module id None: it has no GameModule; its components start from the scene
Assemblies FishMMO.Water (Scripts/), FishMMO.Water.Editor, FishMMO.Water.RenderScratch (the water probes), FishMMO.Water.Tests
Depends on World Simulation (the sky, the weather and the scene's water bodies)
Depended on by World Simulation's, Terrain's, Ambient Life's and Naming's tests; World Design; the World Test Bed
Remove together with All seven world modules (World Simulation's tests reference it, and World Simulation takes the rest)
Moved From Assets/Plugins/FishMMO Water in Phase 4 of the core and modules plan, 2026-11-18; the assemblies keep their names

Core seams it uses

Seam What the module does
SurfaceWater (core) WaterSurface registers as the scene's surface source: level, wave height, whether a point is under it, the waves and the daylight under water. The inland renderers read the scene's inland surfaces and currents from it.
WaterQuery.RegisterSea (core) WaterEnvironment registers the scene's simulated tide (and a lava sea), which swimming, wading and drowning read.

The core reaches the water only through these two and references no water assembly.

Removing it

Delete the seven world modules together (see World Simulation and the gate). World scenes then draw no sea, rivers, lakes or lava, and no sea registers with the core's water queries.

What is here

File What it does
Scripts/WaterWaves.cs The sea state: wind in, Gerstner waves out. Evaluated identically on the CPU and in the shader.
Scripts/WaterMesh.cs The camera-centred disc the sea is drawn on, with rings spaced so each is about as wide on screen wherever it is.
Scripts/WaterSurface.cs The component. Holds the sea level, follows the camera, publishes the waves, and turns off what the pipeline cannot support.
Shaders/FishWaterWaves.hlsl, Shaders/FishWaterInput.hlsl The wave sum shared with whatever rides the sea; the one material constant buffer every pass declares.
Shaders/FishWater.shader FishMMO/Water/Ocean.
Scripts/WaterShoreField.cs The depth and distance-to-shore field, built from the scene's terrains: cached under Library/FishMMO/ShoreField in the editor, embedded in the scene by a player build (Editor/WaterShoreFieldBuildEmbed.cs), built live off the main thread otherwise.
Scripts/WaterShore.cs The swash up the beach, its clock (which the breakers keep time with) and the foam memory.
Scripts/WaterBreakers.cs, Scripts/WaterBreakLine.cs The breakers: the break line traced off the main thread, their sheet and their spray.
Shaders/FishWaterBreakerCommon.hlsl The one model of a breaker every pass that draws part of one reads.
Shaders/FishWaterShading.hlsl How the sea is lit and foamed — shared by the ocean and the breakers, so they cannot differ where they meet.
Shaders/FishWaterBreaker.shader, Shaders/FishWaterSpray.shader FishMMO/Water/Breaker and FishMMO/Water/Spray.
Materials/OceanWater.mat The default sea material — the breakers included.
Scripts/InlandWaterRenderer*.cs, Shaders/FishInlandWater.shader Rivers, lakes and waterfalls: channels, flow, falls, wakes.
Scripts/LavaRibbonRenderer.cs, Scripts/LavaMask.cs, Shaders/FishLava*.shader Lava, drawn by the same renderers.

Using it

Add a FishMMO → Water → Water Surface component to an empty object. Its Y is the still-water level, in metres. Assign OceanWater.mat, set the wind, and that is the whole setup — the mesh is built for you and follows whichever camera is rendering.

Scenes cut from a planet by the World Atlas get one automatically. In those scenes world Y is altitude above the water line: the sea sits at y = 0 and the terrain stands at its real height above and below it, so the coastline underfoot is the coastline on the globe. A scene whose lowest ground is above the water line gets no sea at all, and neither does a world with no liquid water on it.

Floating things on it

float surface = water.HeightAt(transform.position);
bool submerged = water.IsSubmerged(transform.position);

HeightAt evaluates the same sea the shader draws — the FFT spectrum's strongest components, summed on the CPU, with the same tide and the same fade over the shallows — so a boat sits in the trough a player can see. The breakers are not in it: inshore of the break line the sea is still water, and something floating there rides that. It is an inverse, not a lookup: waves move water sideways as well as up, so the piece of water that ends up above a given point started somewhere else. Three fixed-point iterations bring it within a centimetre.

Shores and breakers

The FFT cannot break a wave, so it does not try. It is a single height field — one height per point of the sea — and a plunging wave has three: its back, its lip and the face under it. So the sea is a hybrid:

  1. The shallows. From the depth where the sea is whole to the depth where waves break, its amplitude falls smoothly to nothing (FishWaterCalm). The break depth is the sea's significant height over WaterSurface.BreakingIndex (0.78); the waves are whole from ShallowsDepthRatio times that. Both follow the sea state and the tide.
  2. The break line. WaterBreakers traces the contour of that same depth in the same shore field, and lays a sheet along it that the vertex shader raises, curls and lands from the shore's clock. Its base is flat water exactly where the sea has gone flat, it is drawn with a copy of the sea's material through the sea's own shading function, and its textures are read at the sea's own points where they meet — so there is no seam to hide. The beach decides the breaker: spilling on a gentle one, plunging on a steeper one, surging (no curl) on a steep one, none on a cliff. Waves stand up in peaks a few tens of metres apart and the break peels outward from each one — a straight beach would otherwise close out along its whole length at once, like a wall.
  3. The impact zone. Where a lip lands, spray and a splash are thrown and mist hangs downwind — particles worked out on the GPU from the breaker they belong to, with no simulation state. The bore then runs inshore as whitewater on the still sea, reaching the waterline as the swash starts, and leaves foam the memory keeps for a few seconds. Out in the fade band the white caps take a lower bar, following the crests the sea no longer shows.

Look and size live on the ocean material under Breakers (height, barrel, whitewater, edge fade); reach, spacing and particle counts on WaterBreakers.

URP settings this actually depends on

This is the part that bites. Sampling a texture URP has not bound is not an error and does not come back black — it returns whatever was last written to that slot. Left unchecked, the water refracts the previous frame's buffers and foams in mid-air.

Feature Needs Without it
Refraction Opaque Texture on the URP asset Falls back to alpha blending. On in URP-HighFidelity, off in the other two.
Shore foam, soft edges, depth absorption Depth Texture on the URP asset Foam and soft shorelines are dropped; the sea is treated as uniformly deep. Off in URP-Performant.

WaterSurface reads the running pipeline asset and disables each one that cannot work, through global shader keywords — not material keywords, which would write the answer into the .mat and leave it modified in the working tree on whichever machine opened it last. It warns once in the log so a missing effect is never silent.

Under the water

While the camera is below the surface, a full-screen pass (FishMMO/Water/Underwater, driven by the Underwater fields on WaterSurface) fogs everything in front of the camera by the water between — the sea bed, anything swimming, and the surface overhead, which it draws after. What it adds to the view is the light the water scatters toward the eye:

  • Daylight that fades with depth, per colour, integrated along each ray: looking down falls away into dark blue, looking up brightens toward the surface.
  • Shafts of sun (UnderwaterShafts): the caustics' own lens, marched in sixteen steps through the nearest 40 m and cut by the main light's shadow map, so a cliff or a hull shadows the water as well as the floor. The dearest part of the pass; 0 skips the march.
  • Drifting matter (UnderwaterMotes): specks on a world grid, drifting with the current, sinking, and swaying with the swell near the surface.

Looking up, Snell's window shows the actual scene above, bent by the waves when refraction is on.

Cost

Per frame: one transparent draw of a Rings × Segments disc (12k vertices at the defaults), three sines per vertex per wave, and a fragment stage of three sines for the ripples, one reflection probe sample, and two depth samples when refraction is on.

Three things keep it in budget, and all three are also correctness fixes:

  • Waves fade out with distance. Past _WaveFadeStart the crests are closer together on screen than a pixel, so the geometry is under-sampled and aliases into a crawling moiré no anti-aliasing touches. The far sea is flat and the reflection carries it, which is why the horizon of a good ocean is calm.
  • Ripples fade too, and the lost detail is put back as roughness — which is what ripples do to light anyway. Without this the specular highlight becomes a field of crawling sparkles.
  • One material constant buffer, declared once in the header. Every pass of a shader must declare an identical UnityPerMaterial layout or the SRP Batcher silently drops the shader.

There is deliberately no shadow caster pass: water that casts a shadow darkens the sea bed it exists to show through.

Known limits

  • No motion vectors. Under TAA or motion blur the surface does not report its movement, so fast wave motion can ghost slightly. The mesh is set to ForceNoMotion, which is the better of the two wrong answers — the alternative reports the mesh sliding with the camera.
  • No screen-space reflections. Reflection comes from the reflection probe or the sky, so objects standing in the water are not reflected in it.
  • One sea per scene. The wave state is global, which is correct for an ocean and wrong for a lake at a different height beside it.
  • The breakers stop at WaterBreakers.Reach (700 m). Past it the sea's own whitewater carries on alone. On WebGL, which has no threads, tracing the break line again is a hitch of a few tens of milliseconds; lower the reach there.
  • Cloud shadow is an input, not a lookup. WaterSurface.CloudShadow is there for the weather system to drive; nothing drives it yet.

License

FishMMO Water is first-party FishMMO code, licensed under the MIT licence in the repository root's LICENSE. It contains no third-party code as far as is known. Third-party components used by FishMMO are listed in THIRD-PARTY-NOTICES.md at the repository root.