using z-buffer to desaturate color

I’m trying to “desaturate” colors of object positioned to a greater distance from the camera.
I die try this in node editor of a simple scene rendered with blender internal, and the result is in the attached image.
I did try to use “Hue Saturation” and “Hue Correcton Value” but the result are very similar.
The problem is that I get strong artifacts in the border of the object, porbably related to oversampling.

Anybody has any hint how to solve the problem?

Thank you in advance.

EDIT: A good alternative could be to use the z channel to get object “transparent” when positonioned to a greater distance from the camera, than matting the final image results in a similar (maybe better) effect to give the impression of distance.


I succeded a little further simple by changing oversampling settings.
You can see it in attached screenshot.
Desaturate node as well as transparency works as expected.

What I still do not understand is why cycles invert the color in postprocessing…
Any hints?




Whenever working with z-depth you want to be using full-sample settings, absolutely. One other note: You may want to run your Z info through a “Normalize” node rather than a Map Value node; it may help get more consistent results…

thanks benu!
Due to your suggestion I googled a bit try to understand the normalize node, and it seems to “convert” the z values to a range from -1 to plus 1. (http://www.blender.org/development/release-logs/blender-242/blender-composite-nodes/)
At the same time the map value allows you some more settings, as stated also in this tutorial:
http://sites.google.com/site/paprmh/zbuf_float
The important result is that with normalize node cycles render engine starts to work again, the weak part is that you have much less control on settings!
I will try to feed the map value with normalize output !