There are different approaches one could tackle to do it. Distance Fields would do the trick but you have two issues: everything including landscape will affect the material and depends a lot on your scene if thats ok or not, second is that at distance you start to lost precision and the mask size reduces in size, meaning that the far the camera is you will need to add some extra offset to compensate.
The pictures below show how to do it for opaque or translucent /water material:
Join the discord server for project at: Discord when I get time I will do a quick tutorial on different masking options, but I guess you will do just fine with the tip above. Of course the node connection above would multiply anything else placed in there just in case.
