3
$\begingroup$

With RenderLayers Node you can get the Z distance from the camera to the object behind (x,y) which is sqrt((x - xcam)² + (y - ycam)² + (z - zcam)²). But is it also possible to get only the distance along the camera Z axis for each pixel in the rendered image?

Assumed my camera is at (0,0,0) and looks parallel to the X-axis and I have a point at (3,0,4). Then i would get the distance of 5, but it i need it to be 3. The camera could also be somewhere else or rotated in all directions.

Is this possible to read out?

$\endgroup$
3
$\begingroup$

You can achieve this using cycles' camera data node. One of the outputs on this node is the view vector, which can be separated to x, y and z.

Using a simple node setup you can display only the Z distance from the camera in grayscale values.

In the example below I used the light falloff node to enhance the contrast (the Suzanne model is rather small and all the distances were small as a result, something that produced a low contrast whitish image, before contrast was added).

EDITED: replaced the seprate RGB with separate XYZ (does the same thing, but this demonstrates what's happening more clearly) and added an invert node so that farther values are darker (which is more intiuitive).

Camera Z Distance

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.