Depth of Field - Gradient Function in Compositor?

WARNING: Some people got freaked out by the awesomeness of my dumb questions and incorrect language. So please ignore the little mistakes, missing knowledge, be sure that I´ve googled my questions before with no results and, please, answer in a gentle way. Thanks. :slight_smile:

I´m modeling a car racing scene in Blender at the moment; that´s the WIP:
(also on flickr: https://www.flickr.com/photos/139439176@N08/31743322790/in/dateposted-public/ )


As you can see, there´s a long road fading out into the blackness (final picture will be night time), and I want some depth of field on it. I tried the DOF settings of the camera, and because my scene is quite big I used radius. My focus point will “drive” right behind the large rock at the side of the road, the rest of the background should be blurred out (to create some action feeling with cop lights :cool:).

I would use a radius of 0.2;
First, the original image:


And that´s the image with DOF radius 0.2:


Now the background is nice and blurry, but the foreground is blurry aswell! I can fix this by decreasing the radius amount, but my background won´t be blurry anymore (logically).

I want to achieve something like a gradient function, sharp up to 10 “real” meters, than blur out.
Someone knows a node setup for the compositor? I tried to use z depth and defocus node, but achieved just same results with that, and I have to say that I don´t know how to use the composiotr quite well. :no:

“Easy to understand” answers may be really cool, and thanks all of you beforehand!
NGCHunter2

You have to modify the z buffer values to get rid of the foreground blurring. Basically you must clamp the lower z buffer values to your focus distance using math nodes, this way they get the same amount of blur as the focus plane. Z buffer contains distance from camera, so if you for examle want to have everything up to 10 units to be in focus, clamp all smaller values to 10. It is easiest to do with math node set to maximum operation and setting the second input to your desired distance value. And don’t forget to setup the defocus node to focus on that same distance.