onno van braam
computer graphics, webdevelopment

This tutorial will describe how to use the Lens Blur filter in PhotoShop on your renders, using a ZDepth pass.

A ZDepth pass is a black and white image which gives the depth in the z-direction (viewing vector, z component). I will describe in short how to make this pass and then what to do with it.

First of all: you need an actual scene where you want to apply the Depth of Field on. In my case I chose my latest project, which was an artists impression of the center console of the Bugatti Veyron 16/4 (the car).
On the next two screens you can see my camera (you need a camera to do all this! always use camera's to fix certain views on your model) from the top view and the view through the camera.

Select the Camera, and in the Modify panel go to the parameters and then to the environment ranges. Click the checkbox 'Show' and change the Near and Far ranges to what you want as a 'start' and 'end' point of your focal area. Basically you want as much contrast as possible throughout your whole image, and thus try to tweak the Near and Far ranges so that they ...

My settings for this scene were 3000 and 4500 roughly. Remember those values, we will be using them later!

Go to the Material Editor, make a new Standard material, set the self-illumination to 100, click the diffuse slot...

...select Falloff...

...set the Type to Distance Blend...

...and the Near and Far ranges so they match your ranges in your Camera.

Apply this material to all your visible objects in your scene, delete all your lights, set the renderer to Scanline and press shift + q or F9 (quick render).

If everything is correct, you should have something like the following:


Click image for full-size.

Save it to a new file (something like Dash 015 Z Cam04.jpg for instance).

Here's my original render onto which we will apply the DoF trick.


Click image for full-size.

Open up PhotoShop, and load your original render, copy it to a new file (never use the original render when you edit it), and press ctrl + j to duplicate it once more:

Add a new Layer Mask by going to Layer > Layer Mask > Reveal All

In the Layers Panel of PhotoShop (the one below your Navigator Panel usually) you now see the new layer mask.

Click the mask in the Panel so that it gets those little brackets around it and then click the Channels Tab.

Open your ZDepth pass image, copy it (select all, ctrl + c), close it, and paste it into the empty channel (so not into the R, G, B ones!) but in the one we just added.

Go back to the Layer Tab and you can see your mask there...

...and you see it in action too; our image has a reddish hue to it! Oh no!


Click image for full-size.

Not to worry though. Now for the magic: go to Filters > Blur > Lens Blur...

set the Depth Map to Layer Mask, if it isn't already. Make sure Preview is ticked too.

Play with the settings until the result looks how you want it.

The most important settings are:
Blur focal distance: this determines where your focal point it, so where it is sharp
Iris > Radius: the amount of bluriness

All the other ones are not as important, but are great for more tweaking and optimizing.

When you're done, click OK.

What the hell? It doesn't look at all like what we just saw in the preview! CURSES!

It's the Layer Mask that does the damage here; it makes all the white areas in the ZDepth pass more opaque than the black area's. It acts as an opacity map!


Click image for full-size.

So get rid of it, since we already used it for the Lens Blurring.

DELETE! GO AWAY!

Now we're talking; this is like what we saw in the Lens Blur preview window.


Click image for full-size.

It looks pretty good, but there are some problem area's, such as the one I circled here. The blurring isn't very smart and thus overlapping area's don't really smooth out. In this case the CD player was properly modeled and thus was empty inside, the ZDepth was larger there (scroll up to see it in the ZDepth pass).


Click image for full-size.

The solution? Manual blurring, using the Blur Tool (press R in PhotoShop). Set the feather tip to something appropriate and fix what needs to be fixed without messing up the nice effect created by Lens Blur.

Voila!


Click image for full-size.

And the original render (straight from 3D Max, low VRay settings, don't tackle me on the aliasing please. :)), for completeness.


Click image for full-size.

Some other renders of the same scene, with different camera's and varying amounts of DoF:


Comments

Etta
2012/01/09
It's sokpoy how clever some ppl are. Thanks!
Butler_Bing
2011/03/24
For all those saying that it didn't work for them. I had the same problem! It's not explained very well in the tutorial, but you don't apply the lens blur to the mask. You apply it to the layer. Hence the reason for deleting the layer mask afterwards! If you apply it to the layer mask, you then have to blur the render again which defeats the whole point!

I hope clearing this up makes more people use this tutorial, it's rather handy.
Gamini
2010/09/06
wow excellent work.....had implemented for my <a href="http://www.metasystems.com> ERP system </a>.
aceshigh
2010/07/09
this tutorial doesnt work for me.

When I apply the lens blur, in the preview I only see the mask being blurred, not the the image.

also, after applying the lens blur, the ONLY thing I see is that same reddish effect but now it is blurred!
Sam
2010/01/21
ckrzysiek: That is done with the "Blur focal distance" setting in the Lens Blur filter in Photoshop, as described above.
With that setting, you basically choose how much Photoshop should offset the black to white of the alpha channel and for example; see grey as white, black as grey and white as grey. ABCD becomes CDAB.

But, all this is useless since you can just add the Z-depth render element and have Max pop out a separate Z-depth render along side the original render automatically.
ckrzysiek
2009/12/15
I just don't get one thing. On your depth mask the left part (first plan) of an image is completly white. Why then after lens bluring it becomes blured too? I want to achieve a macro photography effect and I want the front and back to be blured as the middle stays sharp. Although I'm doing what you said or using z-depth pass I always have the first plan (front) sharp and the near/far parameters of the camera only regulates how fast the blurriness changes... Any solutions?
Cheers!
ckrzysiek
2009/12/15
I just don't get one thing. On your depth mask the left part (first plan) of an image is completly white. Why then after lens bluring it becomes blured too? I want to achieve a macro photography effect and I want the front and back to be blured as the middle stays sharp. Although I'm doing what you said or using z-depth pass I always have the first plan (front) sharp and the near/far parameters of the camera only regulates how fast the blurriness changes... Any solutions?
Cheers!
Phil
2009/08/08
Fantastic tutorials! managed to fleece MAX from a bankrupt company, (it was probably the price that sent them down lol) i have a million and one questions, but will ask just one.... how did you do the brushed aluminium facing? im not after a tutorial, just a "PS", "3ds", "PS + 3ds maps" type of answer... many thanks, great work!
Phil
2009/08/08
Fantastic tutorials! managed to fleece MAX from a bankrupt company, (it was probably the price that sent them down lol) i have a million and one questions, but will ask just one.... how did you do the brushed aluminium facing? im not after a tutorial, just a "PS", "3ds", "PS + 3ds maps" type of answer... many thanks, great work!
Cameron
2009/07/31
Just tried it out, works a treat and is a great way to have customisable DOF... nice work Onno!
Peter
2009/02/23
The fullsize pictures doesn't work, its linked wrong...
Your folder should be /depth_of_field/
not /depthoffield/... Other then that, great tutorial ;)
avijit
2008/11/18
wow........ great work
zhouliwei
2008/07/01
gan ni a zuo de tai niu bi le!
chu ge xiangxi jiao cheng a
Thanks
Onno
2008/05/05
Thing is: I want to be able to control the ZDepth layer that comes out and not have it 'auto-generated'.
I know that with VRay you can pretty much render out any pass you want with the Render Elements option, but to be honest: it sucks for almost any layer (which is a big bummer, VRay would be even more fantastic than it already is if you could actually get all the passes using Render Elements). But in your defense: the ZDepth pass works pretty easy and quite well. :)

I just tried it with scanline and that is indeed easy too; I learned it the way as described in this tutorial, and always used to do it this way.

Thanks for the critical notes, RRDude.
RRDude
2008/04/29
a good tutorial but outdated and more complicated than it has to be. the first half is rather strange considering that 3dsmax and Vray both can automatically render ZDepth images, without all the complicated material setups. and setting up in Photoshop also had some unneeded steps. you don't need to make a "reveal all layer mask" and then fool around with copying and such. just import the ZDepth image into alpha channel, create mask layer for the image and apply blur.
Guy
2008/04/08
You get a lot of ungrateful people posting comments. Know that there are people out there who appreciate what you do, and won't waste your time asking for personal assistance. You are doing a great job!
max
2008/03/05
thanks for not replying but i figured it out now
max
2008/01/23
for some reason it didnt work for me...i applied the elns blur and previewed fine i pressed ok and nothing, nothing at all changed no matter what i di...the only wasy i could make it work was to to reick click on the mask and click subtract from selection ofr something like that and then apply the effect on the layer below, anyone got a clue why it didnt work for me?
unfa
2007/10/24
This article is very good. Photoshop makes the DoF effect in just several seconds, when Max needs about 3x that time as without Depth of Field. Maybe someone will create a aplugin doing it completly automatic? Of course with some numbers to set.
Nice Tutorial, rocking renders! I always think: "oh god, i'd like to see them workin'" just to know how are they makin' this
wushi
2007/10/13
Very nice and realistic. Thanx for sharing your know-how.
It's because of people like yourself that newbies like myself get a chance to do something even close to beautifull!
Cheers from Mozambique!
bharat yatna
2007/06/28
thats just realy nice tutorial sir and thank u for sharing ur valuable knowledge to this very informatie cg site,
regards n respect
bharat,
Sir jus one ques do u also use nurbs for modeling?
becoz i personaly love to work with all modeling tools to give more precision and want to know from u too!
roland peelen
2007/06/21
I always use zDepth and DOF pro, you should consider that one to ;)

Admin Edit: The plugin looks good, but it does cost . Thanks for the tip though.
initialxy
2007/06/17
duuuude this is the most brilliant tutorial i have ever seen!! it certainly saves a loooot of time. but just wondering would you still suggest using render's default field of depth functionality at certain situations?

Admin Edit: Yes, when you need it to be perfect in a still, then I'd say use the real one. But at the studio where I work, they always do it in post using a similar After Effects plugin. Because for animations you just don't have the time to render out real DOF; compositing all your layers together with baked in DOF is hell too.
Jati
2007/05/31
wow, keren pak!!!
matur nuwuunnn mbaaahhh ^_^
EquiNOX
2007/05/15
Brilliant! That sure would save render time if using actual DOF from any render engine. Thanks for the tips.
Hector
2007/05/12
muy realista
Prodiger
2007/05/10
Nice :)