The fog calculation is based on an undistorted depth buffer, which causes the artifacts you’re noticing. You could fix by also distorting the depth buffer for the fog calculation, but there is another going on that I would recommend fixing instead:
The fog extends above the water plane, as the solution described earlier doesn’t handle looking back up like you are doing completely correct. Often can be ignored, but in case it just looks wrong. To fix you should calculated the fog based on the distance up to, but not beyond, the water plane. If your water plane is flat can be easily calculated inside the shader. If it isn’t totally flat (for example due to waves) you need a more complex solution. For example, you could render the water plane to the custom depth buffer and then take the minimum of the regular and custom depth buffers as the distance to base the fog calculation on.