Page MenuHome

Inconsistent behavior of internal Blender render engine and Cycles regarding the Z pass.
Closed, ArchivedPublic

Description

As described in 'T45409: Incorrect Z values when using Z pass' the behavior of the internal Blender render engine and the Cycles renderer are different. The Z buffer should store the Z component of the original point to be projected as the name suggests and not the distance to the camera center. The internal render engine does this:

--- source / blender / render / intern / source / rendercore.c ---

 457 static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, ShadeInput *shi, ShadeResult *shr)
....
 469                         case SCE_PASS_Z:
 470                                 fp= rpass->rect + offset;
 471                                 *fp= shr->z;
...
--- end ---

As seen in the previous snippet only the Z component is used as a result. This behavior is identical to what OpenGL for example does (see https://www.opengl.org/wiki/Depth_Test and https://www.opengl.org/wiki/Vertex_Post-Processing#Viewport_transform ).

The cycles render engine instead calculates the distance of the projected point the camera center:

--- src / kernel / kernel_passes.h --
 63 ccl_device_inline void kernel_write_data_passes(KernelGlobals *kg, ccl_global float *buffer, PathRadiance *L,
  64         ShaderData *sd, int sample, ccl_addr_space PathState *state, float3 throughput)
...
  84                                 if(flag & PASS_DEPTH) {
  85                                         float depth = camera_distance(kg, ccl_fetch(sd, P));
  86                                         kernel_write_pass_float(buffer + kernel_data.film.pass_depth, sample, depth);
...
--- end ---

For compatibility reasons to the internal engine, OpenGL and the definition of the Z-Buffer the behavior should be changed. It leads to severe issues for compositing making use of the Z buffer values when the engine is switched especially when a wide angle focal length is used. Further a simple inversion of the projection using the camera intrinsic parameters and the Z buffer is not possible anymore.

Regards
Philipp

Event Timeline

Philipp Heise (phh) raised the priority of this task from to 90.
Philipp Heise (phh) updated the task description. (Show Details)
Philipp Heise (phh) added a project: Cycles.
Philipp Heise (phh) edited a custom field.

I persist to think Cycles' results are much more consistent… ;) But let’s let Sergey decide here. :)

@Thomas Dinges (dingto) and @Martijn Berger (juicyfruit) may also be interested.

Bastien Montagne (mont29) lowered the priority of this task from 90 to Normal.Jul 12 2015, 12:08 PM
Sergey Sharybin (sergey) changed the task status from Unknown Status to Unknown Status.Jul 13 2015, 2:17 PM

This is an intentional behavior of Depth pass in Cycles which actually matches to how other modern render engines works (i.e. LuxRender). Don't think incompatibility with BI renderer is a good reasoning to change the behavior and break all the existing setups now.