I don’t see why your media couldn’t be variable density as long as it never extends beyond the bounds of the geometry. I have done it as well as user dpenny.
It is just expected that your texture reaches black right at the geometry edge. Maybe you could also just fade the value to 0 near the edge since by definition you know how far the ray is from the backface with this technique.