Special request: "double depth maps" I have a particular request:

For each pixel of an image, I would like to know at what distance the ray first entered the mesh and at what distance the ray last exited the mesh of an object.

In fact, I need to generate not only the "visible" depth map of an image, but also the "invisible" depth map. 
Those would consist in two point clouds that would act like a "mould" for my object.

Would it be possible to solve this with a Python script?
Should I loop over each pixel and call the ray_casting function? I'm afraid it would take a long time to compute (I have many images to generate).

What functions would you use? Any help on how to code this is welcomed, I am Blender beginner.

Thanks
Here is an example setup for rendering both front and back depth using red and blue channels with Blender Cycles. 

We are rendering "depth" through Cycles emission that mixes with transparency so we can receive emission from the backfacing surface as well. In this setup the emission value is derived from world space Z-coordinate and orthographic camera is facing down.



Red emission receives depth as is, so a face that has Z-coordinate of 0 is black and 1 is fully red. Red depth is multiplied by inverse of Transparent Depth so we are only receiving it from the front surfaces where the value is 0 and inverse is 1.

Blue emission receives inverse of depth, so a face that has Z-coordinate of 1 is black and 0 is fully blue. Blue depth is multiplied by the Transparent Depth so we are only receiving it from the backfacing surfaces where the value is 1.