Offset Gradient by surface?

I guess the simplest way to imagine my question is above Sea level Moss & Corrosion.

Trying to get a Linear Gradient to offset by another surface so have been messing around with Light Paths either Transparent Depth or Ray Length but no hope so far. Image attached to illustrate …
Snip-2020-02-09 173315

If you need the literal surface-- the entire shape-- then this is very tricky. Light paths aren’t going to do it, because light paths are going to change depending on whether the camera is above or below sea level (or looking through a window, etc.) It is possible, by getting weights from geometry proximity and turning those into something nodes can read via UV warp or data transfer vertex color, side from where a shrinkwrap inside/outside goes, but all that’s a pain.

If you don’t need the literal surface, then it’s relatively easy-- you can use object coords from some other object, possibly from an empty, and just read one axis of those coords to get distance, side. And this is actually more appropriate for what you’re talking about with regards to sea level, because it’s average sea level that creates corrosion, not each individual wave.

Ok, thanks will give it a try.