> For the complete documentation index, see [llms.txt](https://docs.shadersource.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/tutorials/underwater-caustics-and-swimming.md). Agents can also search and read this documentation through its [MCP server](https://docs.shadersource.io/~gitbook/mcp).

# Underwater, Caustics and Swimming

The view below the surface, light on the sea bed, and a character that wades in and swims.

Ocean Tool 2 draws the sea from below as well as from above: the surface seen from underneath, shafts of sunlight, the line where the lens meets the water, and caustics on the bed. This tutorial tours those, then gives a character the ability to swim.

![Under the surface off the Island's southern beach](https://2855220899-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk51ACJUA5E3mZvLb9h%2Fuploads%2FKqbcq41QR85K6dPb7Q1E%2Fuw_hero.webp?alt=media)

|                  |                                                                                                                                                                                   |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Time**         | About 15 minutes                                                                                                                                                                  |
| **You need**     | An ocean with a baked shoreline ([Ocean and Shoreline](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/tutorials/ocean-and-shoreline.md)), or the Island example map |
| **You will use** | **Simple > Underwater**; for swimming, your character's Blueprint                                                                                                                 |

## Part 1 - Go under

{% stepper %}
{% step %}

### Fly the camera below the surface

There is nothing to switch on. Fly the editor camera down through the surface: the underwater view starts the moment the lens is under.

Open **Simple > Underwater** to see what is drawing it. **Underwater view** at the top is the master switch.

![The Underwater page](https://2855220899-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk51ACJUA5E3mZvLb9h%2Fuploads%2Fd7jUIHS9z9nreHzqx723%2Fuw_page.png?alt=media)
{% endstep %}

{% step %}

### Look up

**Render surface from below** draws the underside of the waves, with the sky and the land bent through it in a bright window overhead and dark water reflected round it.
{% endstep %}

{% step %}

### Shape the light

| Row                 | What it does                                                                                                                                                                                                            |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Sunlight shafts** | Beams of light radiating round the sun. **Intensity** is how bright they are; **Spread from the sun** is how far from the sun's direction they show; **Contrast** how sharp the beams are. They need caustics to be on. |
| **Motes**           | Drifting specks in the water round the camera, lit by the light that reaches them. They give the water depth as you move.                                                                                               |
| **Density**         | How murky the water is: how soon things fade into its colour. 0 turns the underwater fog off.                                                                                                                           |

The water's colour under the surface is the sea colour you chose on the **Sea** page.

![Sunlight shafts on and off](https://2855220899-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk51ACJUA5E3mZvLb9h%2Fuploads%2F0UjPAEbA5aRewr4Xes8O%2Fuw_shafts.jpg?alt=media)
{% endstep %}

{% step %}

### Cross the waterline

Bring the camera up until the lens is half in and half out of the water. The **Waterline** category draws what you see there:

* **Meniscus** - the bright line where the water climbs the lens.
* **Waterline lip** - the thin band of water bent against the glass.
* **Underwater fish-eye** - below the line the view bends like a wide lens behind a flat port: bowed lines, colour fringes and darker edges.
* **Lens wash (surfacing)** - water left on the lens as the camera comes up, draining down and drying in streaks.

![The camera at the waterline](https://2855220899-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk51ACJUA5E3mZvLb9h%2Fuploads%2F8Av3VA35Zz0K9gWoJWrQ%2Fuw_waterline.jpg?alt=media)
{% endstep %}
{% endstepper %}

## Part 2 - Caustics

Caustics are the moving net of light that the waves focus onto the sea bed. They show from above, through shallow water, as well as from below.

{% stepper %}
{% step %}

### Choose how they are made

On the **Underwater** page, under **Caustics**, the **Caustics** dropdown has three choices:

| Choice                       | What it is                                                                           |
| ---------------------------- | ------------------------------------------------------------------------------------ |
| **Traced light**             | Light traced through the live waves onto the bed. The best looking, and the default. |
| **Animated pattern (cheap)** | A moving pattern of focused light carried by the waves. Traces no light.             |
| **Off**                      | No caustics.                                                                         |

![Traced light, the animated pattern, and off](https://2855220899-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk51ACJUA5E3mZvLb9h%2Fuploads%2FWDN5Ck8b7lQmRNAGGftf%2Fuw_caustics.jpg?alt=media)
{% endstep %}

{% step %}

### Set how strong they are

**Strength** is how clearly the caustics show: 0 is none, 1 the full pattern, and the default is 0.25. **Brightest lines** caps how bright the lines can make the ground. **Shallow fade depth** is how deep the water must be before they reach full strength, so they fade in from the water's edge.
{% endstep %}

{% step %}

### Decide where they show

* **Caustics in the wash** - draw them in the thin sheet of water running up the sand as well.
* **Light shafts from above** - seen from above, draw the beams of light going down into clear water.
  {% endstep %}
  {% endstepper %}

{% hint style="info" %}
**Traced light reaches a set distance.** The **Caustics Traced Light** category has **Traced light distance** (40 m by default) and **Traced light resolution**. Past that distance the animated pattern takes over, so the far bed is never bare.
{% endhint %}

## Part 3 - A character that swims

### Try the example first

Open `L_OceanTool2_Island` or `L_OceanTool2_SurfCove_SimulatedShoreline`, press Play, and choose **Third Person** in the menu. Walk down the beach and into the water.

| Control                | On land    | In the water |
| ---------------------- | ---------- | ------------ |
| **W A S D**, mouse     | Walk, look | Swim         |
| **Shift**              | Sprint     | Swim faster  |
| **C** or **Left Ctrl** | Crouch     | Dive         |
| **Space**              | Jump       | Come up      |

The character wades until the water is too deep to stand in, then swims at the surface, riding the waves. Under water it holds its breath; when the breath runs out it is pushed back up.

![The example character swimming off the beach](https://2855220899-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk51ACJUA5E3mZvLb9h%2Fuploads%2FB9QHNbwvVJT3f6dZ6yQ1%2Fsw_swim.jpg?alt=media)

### Add swimming to your own character

Any Character can swim - one using the engine's Character Movement component, or your own.

{% stepper %}
{% step %}

### Add the component

Open your character's Blueprint, press **Add** and choose **Ocean 2 Swimming**.

With one ocean in the level it finds it by itself. With several, set its **Water**.
{% endstep %}

{% step %}

### Give it controls for diving

Swimming along needs nothing new: your existing movement input moves the character - along the water at the surface, where the camera looks under it.

For going down and up, call **Add Vertical Input** every frame the key is held: -1 to go down, 1 to come up. For a sprint key, call **Set Fast Swimming**.
{% endstep %}

{% step %}

### Give it animations

Set **Tread Montage**, **Swim Montage** and **Underwater Montage** on the component. It plays them, looping, on your mesh's animation Blueprint, which needs the montages' slot - the templates' **DefaultSlot**.

Or leave them empty and blend swimming in your own animation Blueprint from **Get Swim State** and **Is Treading Water**.
{% endstep %}

{% step %}

### Turn foot IK off while swimming

Foot IK left on plants the feet on the sea bed wherever the bottom comes within reach, and pulls the swimmer down. Turn it off while the character swims.

The plugin's own swim animations carry a curve for this, **Ocean2FootIKOff**: on your foot IK node, set **Alpha Input Type** to **Curve** and **Alpha Curve Name** to `Ocean2FootIKOff`, with a scale of -1, a bias of 1 and the result clamped to 0-1.
{% endstep %}

{% step %}

### React to running out of breath

Bind **On Out Of Breath**. It fires when the breath runs out under water, and again every **Out Of Breath Interval** while the character stays under - the place to apply damage. **Get Breath** returns 0 to 1 for a breath bar.
{% endstep %}

{% step %}

### Make it ripple the water

Add an **Ocean 2 Wake Source** component to the character and turn on **Wakes** on the ocean's **Buoyancy & Wakes** page. The swimmer now leaves a wake, and in the simulated shore it presses the water and churns it white behind it.
{% endstep %}
{% endstepper %}

## Something not right?

| What you see                                    | What to check                                                                                                                                                                                |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Nothing changes under the surface               | **Underwater view** is on. On Shader Model 5 there is no underwater view - see [Troubleshooting](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/tutorials/troubleshooting.md). |
| No caustics                                     | **Caustics** is not **Off**, and **Strength** is above 0. Caustics need a bed to fall on: check there is ground under the water.                                                             |
| The character never swims                       | The water must be deep enough over the ground (**Swim Depth**, 1.5 m). Something else holding the movement in flying mode also stops it.                                                     |
| It sinks, or floats too high                    | **Float Line**: where your swim animations put the water above the character's feet.                                                                                                         |
| It drops under or rides on top in shallow water | Foot IK is planting the feet on the bottom: see the step above.                                                                                                                              |
| No swim animation plays                         | The animation Blueprint needs the montages' slot (**DefaultSlot**), after its state machine.                                                                                                 |
| No ripples round the swimmer                    | **Wakes** is on, and the character has an **Ocean 2 Wake Source**.                                                                                                                           |

## Where next

* [Swimming](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/how-to-use/boats-buoyancy-and-wakes/swimming.md) - every setting of the swimming component.
* [Simple Tab](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/how-to-use/ocean-tool-2-editor-mode/simple-tab.md) - the Underwater page row by row.
* [Performance and Scalability](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/tutorials/performance-and-scalability.md) - what the underwater view and caustics cost.
