# 3. Shoreline Foam and Noise Part of [[Water and Stylized Surfaces]]. Back: [[2. Depth Fade with Scene Depth Difference]]. Next: [[4. Vertex Waves and a Shared Height Function]]. > [!warning] Code not compiled in Unity > Described from Shader Graph 17.5.0 node docs (Gradient Noise, Voronoi, Time). Not compiled in the Editor. Foam is the same depth signal as part 2, thresholded and broken up so it does not look like a smooth halo. ## 3.1 A foam mask from meters Add Blackboard properties: | Property | Type | Suggested default | |---|---|---| | `FoamColor` | Color | Off-white, alpha 1 | | `FoamDistance` | Float | `0.35` (meters) | | `FoamNoiseScale` | Float | `8` | | `FoamNoiseStrength` | Float | `0.5` | From the `DepthFade` subgraph, take **Meters** (the clamped, non-negative Eye difference). 1. **Divide** Meters by `FoamDistance` and **Saturate**. This is 0 at the shoreline (or on anything flush with the surface) and 1 once the water is `FoamDistance` meters deep along the view ray. 2. **One Minus** so foam is **1** at the shore and **0** in deep water. 3. Break the edge up. Official nodes you can use without inventing anything: - **Gradient Noise** on **Position** (World) XZ, scaled by `FoamNoiseScale`, optionally added to **Time** (the Time node's Time output) times a small speed so the foam crawls. - Or **Voronoi** on the same XZ for a more cellular breakup. 4. **Lerp** or **Multiply** the noise with the mask: a typical pattern is `mask * lerp(1, noise, FoamNoiseStrength)` so strength 0 is a clean band and strength 1 is a noisy one. Then **Saturate**. 5. **Lerp** the part 2 water colour toward `FoamColor` by that mask, and write the result to Base Color. Foam alpha can go to 1 so the shoreline reads solid. Keep foam in the fragment stage. It depends on Scene Depth Difference, which is fragment-only (Scene Depth's official limitation; the difference node is sampling the same buffer). ## 3.2 What this foam will and will not do It foams where **opaque depth is close to the water surface**: banks, pier legs, a ball sitting in the water. That is usually what you want. It will also foam around a character's legs. If that bothers you, the fix is design, not a new node: put characters on a layer that does not write the depth texture you sample, or accept the foam as a contact cue. This series does not add a custom depth pre-pass; [[Custom URP Renderer Features]] is the place to start if you later want a "static scenery only" depth copy. That is out of scope here and would have to be verified against URP 17.5.0's renderer feature API. It will **not** automatically foam on wave crests. Crest foam is a function of the wave height or steepness from part 4 (for example, saturate(`height / crestFoamHeight`)), multiplied into the same `FoamColor` lerp. Add it after the wave function exists, and keep it optional — stylized ponds often look cleaner without crest foam. ## 3.3 Optional: painted foam If a shoreline is too irregular for a single meter threshold (a very flat beach, a painted river), you can also multiply the mask by **Vertex Color** (Vertex Color node, a channel of your choice) and paint the mesh in any vertex-colour tool. The official Vertex Color node is the hook; this series does not require it. Next: [[4. Vertex Waves and a Shared Height Function]].