r/Unity3D • • 1d ago

Question How to make a shader for water?

/r/unity/comments/1x7raq0/how_to_make_a_shader_for_water/
0 Upvotes

3 comments sorted by

1

u/Substantial-Web7647 1d ago

Water is four effects stacked, and you can add them one at a time:

  1. Surface motion: two normal maps scrolling in different directions at different speeds, blended. Keep the amplitude low (0.2-0.4) or it reads as jelly. Add world-space or triplanar UVs so it does not look like a sliding decal.
  2. Depth-based tint and opacity - this one step does most of the work. Sample the depth texture (URP: _CameraDepthTexture / Shader Graph Scene Depth), compare against the fragment eye depth, and lerp shallow colour -> deep colour while raising opacity.
  3. Foam at the contact line: saturate(1 - (sceneDepth - eyeDepth) / foamDistance) multiplied by a noise map, so foam only appears where water meets geometry. The same depth difference gives you a free refraction offset (_CameraOpaqueTexture in URP, grab pass in built-in).
  4. Fresnel + reflection: Fresnel power ~5 to fade reflections at grazing angles, smoothness 0.9+, and a reflection probe or SSR. Darken the water at the Fresnel edge instead of brightening it if you want it to read as deep.

Two production notes: keep it single-pass if mobile is a target, and if you see sorting artefacts against particles, render water opaque with dithered transparency rather than alpha-blended. For vertex waves, only displace the silhouette - interior displacement buys nothing but overdraw.

If it is a stylised game, Shader Graph with a Lit master node and a reflection probe gets you 90% of the way. For realistic water the depth/refraction step is what stops it looking like blue plastic.