This is great that you got this to work. I spent some time trying something similar - to cue off the original terrain's altitude below the water level, and the closer the terrain is to the water level's altitude, the thicker the mask. I couldn't get it to work, as the "altitude" cues off of the water level itself, or seemed to. I gave up on it (for now atleast).
Your work looks promising.