Water
Updated
A Water Mesh is a real-time sea surface with waves, whitecaps, raindrop rings, reflections and caustics; every cached water plane shares one wave simulation and one draw. Four companion components finish the picture: Water Foam for foam where objects meet the water, Water Wetness for wet shores, Water Volume for diving under the surface, and Water Caustics for moving light on the sea floor.
Use them for pools, ponds, lakes, rivers and oceans. Scripts raise storms, react when the camera dives, and tune foam and wetness as things move. For flames, see Fire; for the ground of a shore or lake bed, see Terrain.
Before you start
Section titled “Before you start”- Entities and components. Each effect is a component you read with
getComponent, change withsetPropsand switch withsetEnabled. See Components. - Signals. Water Volume events reach scripts through a Signal Emitter on the water entity. See Scripting.
- Tweens. Smooth changes, such as a storm building up, use
Tween.value. See Animation. - Caching. Water joins a shared pool when its entity has a Cache Mesh. See LOD and caching.
| Component | Type | What it does |
|---|---|---|
| Water Mesh | comp-water-mesh | Real-time water surface with waves, foam, rain, reflections and caustics. |
| Water Foam | comp-water-foam | Makes water foam where this entity meets the water, and in its wake as it moves through it. |
| Water Wetness | comp-water-wetness | Makes this entity look wet where the water and its waves meet it, like wet sand on a beach. |
| Water Volume | comp-water-volume | Lets the camera go under this water: water-coloured fog as far as its clarity, the waves seen from below, drifting specks. |
| Water Caustics | comp-water-caustics | Paints moving caustic light on this entity where it is under the water, seen while the camera is under a Water Volume. |
Water Mesh
Section titled “Water Mesh”WaterMeshComponent is required on a Water Mesh entity (ent-water-mesh). It draws a square plane of ocean waves, whitecaps, raindrop rings and caustics, reflecting the sky and the sun. You see the scene through it: the floor bent by the waves and fading into the water’s tint with depth.
| Prop | Type | Default | Description |
|---|---|---|---|
size |
number |
20 |
Metres across the plane. |
color |
string |
'#0e4d64' |
Water tint: the colour deep water fades to. |
waveHeight |
number |
0.3 |
Average height of the tallest third of the waves, in metres, at least 0.01. |
waveLength |
number |
8 |
Typical wavelength, in metres: around 1.5 for a pond, 10 or more for open sea. |
windDirection |
number |
0 |
Where the wind blows the waves, in degrees around the up axis. |
foam |
number |
0.5 |
Foam amount, 0 to 1: the whitecaps, and the foam around Water Foam sources. 0 for none. |
clarity |
number |
3 |
Metres of water through which the floor stays visible from above. |
caustics |
number |
0.8 |
Brightness of the caustic light on the floor, 0 to 1. 0 for none. |
rain |
number |
0 |
Raindrop rings on the water, 0 to 1. 0 for none. |
rainSize |
number |
0.2 |
Metres across a raindrop’s ring, 0.05 to 2. |
Every prop belongs to its own plane: rain on one lake never rains on another, and a pond can ripple next to a sea of long swells.
- Lighting. The sun’s glint and the light through wave crests come from the scene’s first Directional Light. Without one, the water reflects only its environment. See Lighting.
- Planes are horizontal. Waves rise along the world’s up axis whatever the plane’s rotation.
- Headsets. A headset draws the water once per eye. Its reflections show the environment only. In passthrough AR the water is a lit, slightly transparent tint.
- Pooled or standalone. With a Cache Mesh on its entity, the plane joins the shared water pool: every cached plane is one instanced draw, but pooled water cannot be clipped by a Mask. Without a Cache Mesh, the plane draws its own mesh, costs its own draw call, and a Mask can clip it.
- Editor. The sea moves only while a water plane is selected; in play it always moves.
Water Foam
Section titled “Water Foam”WaterFoamComponent goes on Primitive Mesh, model, Kit Piece, Group and Camera entities. It makes the water foam where its entity meets it: a boat leaves a trail that dissolves behind it, a bobbing buoy pumps out rings, a ramp into the sea foams along its shoreline. It is visual only, with no physics. Objects without one never foam.
| Prop | Type | Default | Description |
|---|---|---|---|
shape |
'sphere' | 'box' |
'sphere' |
What meets the water: a sphere of radius, or the box around the entity’s own meshes. |
radius |
number |
0.6 |
The sphere’s radius, in metres. |
strength |
number |
1 |
Foam amount, 0 to 1. |
offsetY |
number |
0 |
Vertical offset from the entity’s origin, for example a camera’s waist. |
- A sphere foams a circle where it cuts the water. Use it for round things such as a buoy or a rock.
- A box foams along where the entity’s box crosses the water, for a hull or a sloping ramp.
- Each plane’s
foamscales it: atfoam0 the plane shows no foam at all. - Foam is kept over the 64 m of water in front of the camera, left by the 8 sources nearest it.
Water Wetness
Section titled “Water Wetness”WaterWetnessComponent goes on Primitive Mesh, model and Kit Piece entities. It makes its entity look wet where the water meets it: soaked where the waves wash over, damp where they reached lately, drying over time. Wet sand on a beach, the foot of a rock in the sea. It darkens what is drawn with an overlay, so the entity’s material is never changed.
| Prop | Type | Default | Description |
|---|---|---|---|
reach |
number |
0.3 |
Metres above the highest wave reach that stay damp. |
evaporation |
number |
8 |
Seconds the surface takes to dry once the waves stop reaching it, 2 to 32. |
strength |
number |
1 |
How wet it looks, 0 to 1. |
It follows the water plane nearest it. With no water in the app it draws nothing. Skinned and instanced meshes stay dry.
Water Volume
Section titled “Water Volume”WaterVolumeComponent goes on a Water Mesh entity and lets the camera go under the water. Below the surface everything fades into the water’s tint, darker the deeper you go; looking up, you see the waves from below with a bright circle of sky; bubbles and sand drift around you.
| Prop | Type | Default | Description |
|---|---|---|---|
depth |
number |
20 |
Metres below the surface the water fills, at least 0.1. |
particles |
number |
0.5 |
Bubbles and sand grains in the water, 0 to 1. 0 for none. |
clarity |
number |
15 |
Metres you can see through the water from inside it, at least 1. |
| Member | What it is |
|---|---|
underwater |
Read-only. true while the camera’s whole lens is under this water, as of the last frame. It turns true with submerge and false with emerge. |
The volume is the plane’s square, from its surface down depth metres. Give each tile of a tiled lake its own volume. It is drawn in the world, not as a screen effect, so it looks the same in both eyes of a headset.
Water Volume events
Section titled “Water Volume events”With a Signal Emitter on the water entity, the volume tells scripts when the camera’s lens crosses its waterline. Events are sent in play only.
| Event | EventType constant |
When |
|---|---|---|
Water |
Event |
Part of the lens went under the waterline. |
Water |
Event |
All of the lens is under: the underwater fog takes over. |
Water |
Event |
Part of the lens came back out. |
Water |
Event |
All of the lens is out. |
Each event’s data is empty. A full dive sends enter, submerge, emerge, exit, in that order; a dip that never goes all the way under sends only enter and exit. Swimming from one tile of a lake to the next sends exit from one and enter from the other. Nothing is sent when the volume is removed or switched off, even with the camera inside.
Water Caustics
Section titled “Water Caustics”WaterCausticsComponent goes on Terrain, Primitive Mesh, model and Kit Piece entities. It paints the water’s moving caustic light on its entity where the water covers it, as seen from under the water: sand on a lake bed, hills of a terrain under the sea.
| Prop | Type | Default | Description |
|---|---|---|---|
strength |
number |
1 |
How bright the caustic light is, 0 to 1. |
It shows only while the camera’s lens is in a Water Volume’s water. From above, the water already draws caustics on the floor it shows through its surface.
Examples
Section titled “Examples”1. Raise a storm over the sea
Section titled “1. Raise a storm over the sea”This script turns a calm sea into a storm and back. It changes several water props together with one tween, for every tile of a tiled ocean so the tiles stay seamless.
#pragma lifecycle(startup)
const TILES = ['Ocean Tile 1', 'Ocean Tile 2', 'Ocean Tile 3', 'Ocean Tile 4'];const CALM = { waveHeight: 0.3, foam: 0.4, rain: 0 };const STORM = { waveHeight: 2.2, foam: 0.9, rain: 0.8 };
let seas = [];let current = { ...CALM };let tween = null;
function applyWeather(from, to, t) { current = { waveHeight: from.waveHeight + (to.waveHeight - from.waveHeight) * t, foam: from.foam + (to.foam - from.foam) * t, rain: from.rain + (to.rain - from.rain) * t, }; for (const sea of seas) sea.setProps(current);}
function changeWeather(to, seconds) { if (tween) tween.stop(); const from = { ...current }; tween = Tween.value(0, 1, (t) => applyWeather(from, to, t), { duration: seconds, ease: Ease.InOutSine });}
function startup() { seas = TILES.map((name) => findEntity(name)).filter(Boolean).map((tile) => tile.getComponent(WaterMeshComponent)); applyWeather(CALM, CALM, 1);
on('weather/storm', () => changeWeather(STORM, 12)); on('weather/calm', () => changeWeather(CALM, 20));}One tween changes wave height, foam and rain together on four ocean tiles, turning a calm sea into a storm and back.
Press Storm to raise the waves over twelve seconds, and Calm to let them settle. Drag to orbit the camera, scroll to zoom.
- Each tile is looked up once and its Water Mesh kept in
seas.filter(Boolean)drops names that are not in the scene. applyWeatherblends between two weather objects with a factortfrom 0 to 1 and writes the result to every tile with onesetPropseach.changeWeatherstarts from whatever the weather is now (current), so a storm called off halfway calms down from where it got to. A running tween is stopped first so two never fight.waveHeightchanges the size of the waves;windDirectionandwaveLengthare left alone, which keeps neighbouring tiles seamless.
2. A mini pool you can dive into
Section titled “2. A mini pool you can dive into”A garden pool, set up in the editor: a Water Mesh with clear water (clarity: 8) and short ripples, a Water Volume so the camera can go under, a Signal Emitter with the signal pool, Water Caustics on the tiled floor and walls, Water Wetness on the walls, and a beach ball with a Water Foam. The script bobs the ball and reports the dives.
#pragma lifecycle(startup)
function startup() { const ball = findEntity('Beach Ball'); Tween.to(ball.position, { y: ball.position.y + 0.06 }, { duration: 1.8, ease: Ease.InOutSine, repeat: Infinity, yoyo: true, });
on('pool', (event) => { if (event.eventType === EventType.WaterVolume.Submerge) log('Under the water: caustics on the floor, bubbles round you'); if (event.eventType === EventType.WaterVolume.Emerge) log('Breaking the surface'); if (event.eventType === EventType.WaterVolume.Exit) log('Back in the air'); });}A garden pool of clear water: caustic light dances on its tiled floor, the walls are wet at the waterline, a beach ball bobs with foam round it, and a Water Volume lets the camera go under the surface.
Drag to orbit round the pool. Scroll in to dive under the surface: the water fogs the view, bubbles drift past and caustics play on the floor. Scroll out to come back up.
- From above, the Water Mesh draws the floor through the surface with its own caustics; under the surface, the Water Caustics on the floor and walls take over, so the light never shows twice.
Submergecomes once the whole lens is under the waterline, when the water’s fog takes over;Emergeas soon as part of it comes back out, andExitonce all of it is out.- The ball’s foam follows it as it bobs: Water Foam rings whatever meets the water, moving or not.
Snippets
Section titled “Snippets”1. Muffle sound and wet the lens when diving
Section titled “1. Muffle sound and wet the lens when diving”The lake tile has a Water Volume and a Signal Emitter with the signal lake. The camera entity, named Main Camera, has a Lens Drops effect (see Post-processing). This script muffles the music under water and leaves drops on the lens as the camera comes back up.
#pragma lifecycle(startup)
function startup() { const music = findEntity('Music').getComponent(AudioComponent); const drops = findEntity('Main Camera').getComponent(LensDropsEffectComponent); drops.clear(0);
on('lake', (event) => { switch (event.eventType) { case EventType.WaterVolume.Enter: drops.clear(); break; case EventType.WaterVolume.Submerge: music.setProps({ volume: 0.2 }); break; case EventType.WaterVolume.Emerge: music.setProps({ volume: 1 }); drops.play(); break; } });}drops.clear(0)wipes the lens at once at startup, so the effect is ready and dry.Enterfires as soon as part of the lens touches the water: the lens is wiped, since a lens under water has no drops on it.Submergefires only once the whole lens is under, so the music drops to 20 % then, not at the first splash.Emergerestores the music and starts the drops as the lens comes out.- The events have no data; the script only compares
event.eventTypewithEventType.WaterVolumeconstants.
2. Foam that follows a boat’s speed
Section titled “2. Foam that follows a boat’s speed”A boat with a box-shaped Water Foam should foam hard when it moves fast and barely at rest. This script measures its speed and eases the foam strength.
#pragma lifecycle(startup, update)
const FULL_SPEED = 6; // metres a second for full foamlet foam;let lastPosition = new THREE.Vector3();const position = new THREE.Vector3();let strength = 0.2;
function startup() { foam = self.parent.getComponent(WaterFoamComponent); foam.setProps({ shape: 'box', strength }); self.parent.getWorldPosition(lastPosition);}
function update(dt) { if (dt === 0) return; self.parent.getWorldPosition(position); const speed = position.distanceTo(lastPosition) / dt; lastPosition.copy(position);
const target = 0.2 + 0.8 * Math.min(1, speed / FULL_SPEED); const next = strength + (target - strength) * Math.min(1, dt * 2); if (Math.abs(next - strength) < 0.01) return; strength = next; foam.setProps({ strength });}- The script sits on the boat.
shape: 'box'fits the foam to the hull along its longest side. - Speed is distance travelled since the last frame divided by the frame time. The vectors are created once and reused.
- The strength eases toward its target (
dt * 2is roughly half a second of smoothing) instead of jumping. setPropsis skipped when the change is below 0.01, which avoids writing nearly identical values every frame.
Performance
Section titled “Performance”- Water: while water is in view, the scene is drawn once more each frame at half resolution to show what is under and around it. On phones and standalone headsets, prefer one or a few planes, and pool tiles with a Cache Mesh.
- Foam and wetness: with no Water Foam source and no Water Wetness in the app, nothing extra runs. With one, the water adds one small pass a frame. Wetness costs one extra draw per mesh of its entity.
- Water Volume: a scene without a volume pays nothing. With one, the water draws both faces, and under the water there are two more draws.
- Water Caustics: one extra draw per mesh of the entity, and only while the camera is under water.
Common mistakes
Section titled “Common mistakes”- Expecting foam without Water Foam. Objects never foam on their own. Add a Water Foam to the boat, buoy or ramp, and keep the plane’s
foamabove 0. - Seams between tiles. Tiles must share
windDirectionandwaveLength. Change onlywaveHeight,foam,rainand colours per tile. - No sun glint. Glints come from the scene’s first Directional Light; add one.
- Listening for Water Volume events without a Signal Emitter. The events only reach scripts through a Signal Emitter on the water entity.
- Using
underwaterfor the first splash.underwaterturnstrueonly once the whole lens is under (withsubmerge). Listen forenterto react to the first touch. - Masking pooled water. Water with a Cache Mesh cannot be clipped by a Mask. Remove the Cache Mesh from planes that must be masked.
- Calling
setPropsevery frame with the same values. Throttle, ease or skip unchanged values, as in the examples.