Blender depth mystery

I am trying to use the depth values from a render. I created the appropriate graph that directly connects the render layers depth pin to an OpenEXR file output. The problem is that the depth values do not match the objects in the scene.

As a simple example, I have used the default scene with a cube at 0,0,0 and a camera placed at 0,-6,0 looking directly at the cube. The distance between the camera and the cube's closest plane is exactly 5.

When I load the EXR file as a matrix of floats, the value at the center is 5.45 instead of 5, both in the default render engine, and in cycles.

I don't know if any of the following information is relevant, but just in case: Image size 1280x720, focal length 35mm, sensor size: 32mm

I would appreciate any ideas of where this discrepancy comes from.

Blender's depth map should work fine. I have tested it and I do get the right distance. How do you load the OpenEXR files? Not all OpenEXR readers are reliable. I have noticed that OpenCV can give inaccurate results (see https://github.com/opencv/opencv/issues/10114).

• This was it. Thanks. I tried loading the file in python using OpenEXR and it works fine. – Photon Oct 17 '18 at 7:52
• So I guess we've established the manual is wrong?... how do you post corrections? – Robin Betts Oct 17 '18 at 11:12

According to the manual,

the depth map is inverse linear (1/distance) from the camera clip start.

so

• it depends on the "Clip start" camera setting

• it shouldn't be read straightforwardly as a distance map, but the distances should be easy to work out

From what is written, it would appear that $$Z_{\rm map} = \frac{A}{(d-{\rm clip_{start}})}\quad\Rightarrow\quad d = \frac{A}{Z_{\rm map}}+{\rm clip_{start}}$$ (I haven't tested it) but it's not clear whether $$A=1$$ or you must empirically determine it.

• On the other hand, actually passing a cursor over the all-white-looking Depth representation in the render window (which is only available if 'Z' is checked as a render pass) returns the distance of a plane in BU from the camera, (exact at the center, increasing towards the edges in perspective, constant in ortho, as you would expect,) no reciprocal, irrespective of the clip start. I'm not kitted up to look at the inside of an EXR at the moment.. – Robin Betts Oct 16 '18 at 11:40