I'm trying to make a material that resembles some kind of liquid; it is opaque where it is thick and transparent where it is thin. I'm planning on mixing a diffuse and glass shader with presumably a custom node (if one doesn't already exist) as Fac.
The diagram above illustrates what I need, showing a camera and a single object (with two physical parts).
I need a node that will give me back a 0 to 1 (ie. black to white) value depending on the distance the camera's rays must travel through the object (the purple lines in my diagram).
Because it wouldn't make much sense for the 'perceived thickness' to simply be the first purple line segment on a ray. It would probably be best if the length of the purple line is the sum of the segments of it on that ray in the object, even if part of the object is physically disconnected from the other parts.
I've look around but I can't find much of anything that seems to fit the bill for what I'm looking for. I was hoping someone has already written a node like this or if there is a node setup I could use.
P.S. I use 2.8, so some older scripts might not work for me.