Simulating an x-ray

I’d like to simulate visually (and also somewhat mechanically) the way an IRL xray would work.
My first thought was to just build a big, nasty, raytracing camera with a bunch of Traces.
My thinking was to take the time/distance between when the trace enters the object, and when it exits like so:

This way I could just use that inner time/distance as my pixel value and voila, xray!
But I havent been able to find any way of getting the ‘exit’ time/location of a trace.
So I thought maybe I could look for an overlapping hit, and when the trace encounters it’s end or a blocking hit, I trace backwards to the backside of the object:

This is pretty hacky, and gets even worse once I account for the fact that multiple objects can physically overlap in the scene:

Whereas the first solution I thought of would be a little nicer in the case of multiple objects:

Any thoughts on how to do this would be appreciated. I’m new to the engine but CS literate, so if there’s a C++ solution that you can think of, please feel free to explain it.

Thanks!