# Changing water color based on depth

I'm looking to make a water shader that colors the water based on its depth. Up until now my water shader that I've used has basically been extremely reflective and only looked somewhat blue because it was reflecting a blue sky. The effect I'm shooting for looks something like the one from the first page in this article.

I don't necessarily need exact shader code, just the gist of how I calculate the color of the pixel based on the depth, while still getting a proper reflection and refraction. I should mention that I already have the water's depth calculated, per-pixel, and I also have working reflection and refraction. All I'm lacking is a color based on depth.

I've tried a bunch of stuff, the next thing I'm considering is actually coloring the terrain that is underwater, and coloring it based on depth.

lerp(shallowColor, deepColor, saturate(depth * depthColorScale));

Here depthColorScale is 1.0 / the depth at which the water should reach deepColor (probably a couple meters, I'd guess). Then treat the result as a fog color applied to the terrain under the water in the usual way: namely, lerp from the terrain color to the fog color based on the length of the refracted underwater eye ray.