Set opacity using DistanceToNearestSurface?

I’m trying to fade the opacity of this water material based on DistanceToNearestSurface, but I can’t seem to get a balance. I want the darker part to be 0.5 opacity and the outside to fade to 0.

I didn’t want to use a fresnel because I wanted the fade to respond to objects in the water. There’s a foam material as well, but you can see the problem with the edge in the 3rd picture (taken with just a basic opacity of 0.8), which is why I’m trying to do this.

Have you seen this guy’s stuff, especially to do with distance fields / water etc

I was looking through his stuff last night, funny enough. I just couldn’t find anything that addressed using them for opacity. Maybe I missed something.

He’s using them to control color etc, but affecting opacity works in the same way. At the foam appears, you can reduce ( or increase ) the opacity, eh?

That’s what I’d thought, but when I tried using the exact same setup I had in my color, it gave me the picture posted in my first post. With the center totally black rather than 0.6.

Ahh I figured it out.