Is there a way to render overlapping geometry as different passes/layers? I want to be able to take a scene and render the geometry as different layers based on their overlapping depth (from the view); ex: by using an index.

For a sphere, the index 1 would be rendering the front surface and index 2 the back surface. Of course, the goal is to be able to render any kind of scene. 

I don't know how this could be done (if it can), EEVEE is probably too limited by the depth buffer workflow; Cycles may have features I'm not aware of which could lead to a solution.

My use case is external deferred compositing of overlapping objects.
I found a way with Cycles for my use case by using the Transparent Depth of the Light Path node.

A transparent shader is mixed with the original shader based on the pass index required. If the transparent depth is equal to the pass index, then it should use the original shader, otherwise it should be transparent.

Node setup:



Sphere 0-1 indexes:



Suzanne 0-3 indexes: