a guide to blender's new float zbuffer
Blender has always had a zbuffer, a special image buffer that contains each pixel's distance from the camera. Until recently, this information was an integer value that was dependant on the clip start and clip end of the camera and somewhat hard to work with. Now blender has a new and much more user friendly zbuffer, zbluf_float. This new zbuffer consists of actual distances (in blender units) from the camera to each pixel of your image. Now, even though you can look at and understand what the zvalues are, you still need to manipulate them a bit to use them in blender.
Most of the time, you are going to need some sort of greyscale representation of this zbuf and that means that you have to condense these distances from their origional values to a 0->1 range.
If you want to get the most accurate gradient, you need to first figure out your scenes depth. (the distance of the closest and farthest pixel of your scene - not including your world background) This can be done easily in just a few steps:
- select your camera and go to your edit buttons (F9)
- toggle show limits (it shows you the camera's range in the 3D windows)
- increase the clip start until the closest object in your scene starts to disappear, then decrease it until everything shows again
- decrease the clip end until the farthest object in your scene starts to disappear, then increase it until everything shows again
Now we know our scene has zbuffer values from about 10 to 45 bu ( the closest pixel is at 10.0310 and the farthest is at 43.9232 in case your are curious) but you are usually going to need a gradient from 0 -> 1 and that is where the map value node comes in handy. It maps a range of values to a new range of values.
The offset value is where you want your 0 (black point) value to be and the size value will deterimine the width of the gradient in terms of blender units (size = 1/ bu). The min and max buttons clip any results to those limits.
Here is a screen cap of 4 different map node setups and their results:
In the top set of nodes, I decided that I wanted a full depth map of my scene and I wanted it to be white (near) to black (distant). This means that I want my gradient to start at 45 ( farthest pixel) so I set offset to -45. I know that my scene is 35 bu from front to back so to condense that to a 0->1 range I set the size value to 1/35 or -.0286. The negative number is because I want the gradient value to increase as it gets closer to the camera.
The second set of nodes is a full depth map again but with black closest. This time I wanted the gradient to start at 10 so the offset is set to -10. I still want a gradient that covers my full scene but this time I want the gradient to increase with distance so the size value is .0286.
The third set of nodes is offset = -30; size = -.1 (1/10). This gives me a gradient that is totally black at 30 bu and farther from the camera and totally white at 20 bu and closer.
the last set is offset = -15; size = 1. notice that the gradient is only 1 bu deep