Is it possible to have render output the distance to the object in every image pixel?
I.e., if you raytrace a scene, you get for every image pixel an intersection point between ray and scene. Is it possible to either have blender output this (x,y,z) point or the distance between the camera and the scene. I only found a way to get the Z-coordinate of the scene - which was a bit of a hack. This is the same for an orthographic camera, but not in a perspective setting, which is what I want.
I need either the actual depth, i.e. the distance from camera to scene in each pixel (when using supersampling, an average over all depths would be just fine), or the scene coordinate of the pixel and the camera coordinates (this is equivalent, just compute the Euclidean distance between those two points to obtain the depth).
Is this possible? How?
EDIT: Just noticed I got the wrong forum section for this. I’m terribly sorry, this one seemed appropriate when I looked, I only read the notification mail after I posted. I’m really sorry.
That method above isn’t working for me. I also would want a good depth output, and I’ve come up with only one good technique, but it has some big drawbacks.
Put a lamp (no shadows) at the same place as your camera, with no other lighting in the scene (no AO). Use the DOF limits tool on the camera to choose your depth point, then copy that number into the distance value for the lamp. Set every object n the scene to a white fresnel material set to a ref of 1. Render your scene with a black background.
Yeah, I know. BIG drawbacks.
I think the method Caab said isn’t working for you because depth can’t be rendered directly (it ranges more than 256, wich is color’s max range). I think you’d get the same result you get using the lamp and black background method, just going to composite and pluging the Z channel to a Normalize (Vector->Normalize) node, then to a Invert (Color->Invert) node, and then to the output.
Anyway this method only gives you a B&W image but not real depth values, and, like gouda, I also want to get the absolute depth of each pixel (relative to the camera, of course). It would be nice to get it as a stream of floats for an easy reading in C++. Maybe it could be done with python, but I don’t have time to learn python, so if anyone knows how to do this let me know please!!!