Distance To Nearest Surface is extremely laggy

Old stuff but your shader kinda makes no sense.
First you divide which is giving you the distance. everything 2cm from the material.
Then you subtract from that.
Then you clamp it back from 0 to 1
Then you increment it again by a power of 4
then you clamp it again… for every pixel on screen if you are dealing with a water surface.

Going to go out on a limb and say that the reason this was laggy is probably the amount of superfluous mathematics on the shader combined to the size of the mesh plane.