I checked the Cycles Z-Depth, studying it to use in conjunction with ouputs from other engines, in a mixed piepeline, and I was surprised to see that Cycles Z-Depth works differently to the other most user render engines out there.
While other engines project the Z-Depth from the film plane, which gives us a linear distance of the scence towards the camera, it seems Cycles uses a pinhole system, which gives a distorted version of the Z-depth, because it’s an spherical projection.
I’m not saying that this is inherently wrong, but makes very difficult to integrate cycles in a mixed pipeline.
Since there is an effort for adopting some industry standards in Blender, like the “Industry Standard” keymap, could be good to have the Z-Depth all other engines use out there.
It’s also interesting that this Z-Depth that we require is already given by Eevee.
Let me show the examples, this is the “correct” Z-depth, the expected one that works in general with any compositing software and in a mixed pipeline, in this case this is Eevee:
And this is the “incorrect” one, that makes very difficult to mix outputs in general, even mixing with eevee could be problematic:
As you can see this is distorted.
This may be a not-so-big effort (it is for me, but from what is said by others here, it’s a trigonometric calculus) so could be great, maybe not replace the Z-Depth as it is right now, but add a Linear Z-Depth option to the passes, so the user can choose which kind of Z-Depth wants, because right now it’s impossible to extract a compatible Z-Depth with Cycles, a Linear one.
As a side not, doing another render with eevee is not an option, it’s ok for a simple scene, but it’s not ok for a production scene with a large amount of instances, and hundreds of millions of polygons.