# 1. Water Mesh and URP Depth Setup Part of [[Water and Stylized Surfaces]]. Next: [[2. Depth Fade with Scene Depth Difference]]. > [!warning] Code not compiled in Unity > Type-checked against Unity 6000.5.8f1 assemblies and described from Shader Graph / URP 17.5.0 docs (see the hub). Not opened in the Editor. Water in a deferred or forward URP frame is a **transparent** surface that draws **after** opaques. The two textures this series reads are produced before that pass: - **Depth Texture** (`_CameraDepthTexture`) — the scene depth after opaques. [[2. Depth Fade with Scene Depth Difference]] and foam use it. - **Opaque Texture** (`_CameraOpaqueTexture`) — a copy of the color buffer after opaques. [[5. Normals Reflections and Scene Color Refraction]] uses it. If those textures are off, the official Shader Graph 17.5.0 docs are blunt: **Scene Depth returns 0.5** in URP, and **Scene Color** has nothing useful to sample. ## 1.1 Turn the textures on Select the **URP Asset** your current Quality level actually uses (Project Settings > Graphics, and Project Settings > Quality — each level can reference a different asset). In the Inspector, enable: - **Depth Texture** — URP 17.5.0 editor source: "If enabled the pipeline will generate camera's depth that can be bound in shaders as `_CameraDepthTexture`." - **Opaque Texture** — "If enabled the pipeline will copy the screen to texture after opaque objects are drawn. For transparent objects this can be bound in shaders as `_CameraOpaqueTexture`." Enable this in part 1 even if you only hook it up in part 5, so you do not have to revisit every Quality asset later. If a Quality level must be cheap (Quest), leave Opaque Texture off on that asset and skip refraction; depth fade and foam only need Depth Texture. A URP Camera can also override both properties. The camera inspector labels (same package source) are again **Depth Texture** and **Opaque Texture**, with a note that generating the depth texture has a cost. For this series, leave the camera on the pipeline default unless a specific camera (a minimap, a reflection cam) should not pay for the copy. > [!note] Unverified here > The Opaque Texture has a downsampling control on the URP asset. I am not pinning a default in this series without looking at the exact 17.5.0 enum labels in the Inspector of a running Editor. Use the pipeline default; if refraction looks blocky, tighten the downsample, and if it is expensive on a Quest quality tier, turn Opaque Texture off ([[6. Quest Cost and Quality Tiers]], [[Profiling and Optimization]]). ## 1.2 Create the graph and material 1. **Create > Shader Graph > URP > Lit Shader Graph.** Name it `StylizedWater`. 2. Open **Graph Inspector > Graph Settings** (the Lit URP target): - **Surface Type: Transparent.** Official Scene Depth and Scene Color docs both warn that opaque graphs may not see a complete depth / color buffer. Water must also *not* write itself into the opaque depth you are about to fade against. - **Blending Mode: Alpha.** - **Render Face: Front** (or Both if you will dive under the surface; Underwater is not in this series). - Leave **Depth Write** in its default for a transparent Lit graph (off). Writing depth from transparents fights the foam and the objects that poke through the surface. 3. Create a material from the graph and keep it on a clearly named material, `M_StylizedWater`. You now have a transparent sheet. It will look like a pale Lit plane until part 2 feeds it colour. ## 1.3 Give it a mesh with enough vertices A default Unity plane is 10×10 quads — acceptable for a pond, not for waves. A 2-triangle quad is useless for vertex displacement. Either: - Build a plane in [[ProBuilder Gray-Boxing and Landmarks]] and subdivide it, or - Generate a grid at edit time with the script below and save it as a mesh asset. `Runtime/WaterMeshGrid.cs`: ```csharp using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif namespace WaterAndStylizedSurfaces { public static class WaterMeshGrid { public static Mesh Create(int quadsX, int quadsZ, float sizeX, float sizeZ) { quadsX = Mathf.Max(1, quadsX); quadsZ = Mathf.Max(1, quadsZ); int vertsX = quadsX + 1; int vertsZ = quadsZ + 1; var vertices = new Vector3[vertsX * vertsZ]; var uvs = new Vector2[vertices.Length]; var normals = new Vector3[vertices.Length]; var triangles = new int[quadsX * quadsZ * 6]; for (int z = 0; z < vertsZ; z++) { for (int x = 0; x < vertsX; x++) { int i = z * vertsX + x; float u = x / (float)quadsX; float v = z / (float)quadsZ; vertices[i] = new Vector3((u - 0.5f) * sizeX, 0f, (v - 0.5f) * sizeZ); uvs[i] = new Vector2(u, v); normals[i] = Vector3.up; } } int t = 0; for (int z = 0; z < quadsZ; z++) { for (int x = 0; x < quadsX; x++) { int i = z * vertsX + x; triangles[t++] = i; triangles[t++] = i + vertsX; triangles[t++] = i + 1; triangles[t++] = i + 1; triangles[t++] = i + vertsX; triangles[t++] = i + vertsX + 1; } } var mesh = new Mesh { name = quot;WaterGrid_{quadsX}x{quadsZ}" }; mesh.vertices = vertices; mesh.uv = uvs; mesh.normals = normals; mesh.triangles = triangles; mesh.RecalculateBounds(); return mesh; } #if UNITY_EDITOR [MenuItem("Assets/Create/Water/Water Grid Mesh (64x64, 20m)")] static void CreateAsset() { var mesh = Create(64, 64, 20f, 20f); var path = AssetDatabase.GenerateUniqueAssetPath("Assets/WaterAndStylizedSurfaces/WaterGrid_64.asset"); AssetDatabase.CreateAsset(mesh, path); AssetDatabase.SaveAssets(); Selection.activeObject = mesh; } #endif } } ``` 64×64 quads over 20 m is a reasonable classroom pond. A lake will want a larger size or a projected mesh; this series stays on one grid so the wave function in part 4 is easy to see. Create a GameObject, add a Mesh Filter (the grid) and a Mesh Renderer (`M_StylizedWater`). Place it so a grey-box bank or a few cubes intersect the plane — you need something behind the water for depth fade to show up. Put the player-side camera where you can see the shoreline. ## 1.4 Check the textures are really there The Frame Debugger (see [[Profiling and Optimization]]) will show a depth copy and, if enabled, an opaque copy before the transparent pass. If Scene Depth later looks like a constant mid-grey fade, come back here: the usual cause is Depth Texture off on the **active** URP asset, or the water graph left on Opaque. Next: [[2. Depth Fade with Scene Depth Difference]].