Faking depth of field in After Effects using a depth pass
I wrote this tutorial because I know many people, like me before, that are searching for a way to use a depth pass in Adobe After Effects. I asked in many forums, both 3D and After Effects ones, to no avail. But someday someone gave the answer in a forum, and I thought I could share this knowledge with you.
This tutorial is non specific to any software regarding 3D.
Generating the depth pass - Importing footage files - Layer placement - Applying the effect - Setting the parameters - Enhancing quality - What's next?
3D softwares offer different approaches on how to generate a depth pass. In some you just check an option and here you go, in some others you'll have to create it.
The easiest way to create a depth pass is to put a constant white shader on all objects. Then, apply a black fog. The fog should start at the camera, and should end where you want the DOF effect to be the stronger/weaker.
Render the normal image (the beauty pass), and then the depth image (the depth pass).
Open After Effects and load the two passes. If prompted to the alpha channel interpretation, check Ignore.
This will cause After Effects to treat the footage files as if they had no alpha channel.
Create a new composition, the size of your rendered images. Put the to passes on it. The beauty pass should be on top of the depth pass.
Select the beauty pass layer, and do Effect > Blur & Sharpen > Compound Blur.
This will bring the Effect window. Click on the Blur Layer drop down menu, and choose the depth pass layer.
You will notice that in the Composition window the effect is present, but very jagged.
For now, the effect is too strong, this is why the image is jagged. In Maximum Blur, put something like 5.
Also, checking the Quality checkbox for each layer will display the layers in full quality.
Well now you should have something much nicer.
If this is the background you want blurred, then check Invert Blur in the Effect window.
Now you should have something like this:
There are few things that you can do to enhance the effect overall quality.
a) Editing the depth pass
You can put a Levels, Curves or any other RGB editing effect on the depth pass.
There are two things to consider:
- Be aware that even if you change the depth layer to make it high contrast,
the changes on the compound blur will be minimal.
- If you choose to do such editing, you will get results only if you render
the depth layer alone with the effects, import this new pass into After Effect
and use this sequence instead of the original one for the compound blur. Or
you can simply put the edited depth layer into its own composition and use this
composition for the compound blur. I don't know why, but using the edited depth
layer itself for the compound blur doesn't change the blur.
b) Creating a new depth
pass
This is different than in a). Here you will create a new composition (name it
Depth Composition), where you will put only the depth layer. Duplicate this
layer. On the top layer, apply a compound blur effect (with the same parameters
as above). Then, put the Depth Composition in the beauty pass composition and
use the Depth Composition for the compound blur.
The only thing you'll notice is a more defined blur, but nothing much.
There are several limitations
to this technique.
- The overall quality is not much superior than with floating points files (like
the Softimage zpic).
- Effect tweaking is pretty limited (except the Maximum Blur setting).
- The effect looks good only with small blur amount. You can see on the example
above that the two middle spheres have a sharp contour, even with the blur,
and the foreground sphere is somewhat blurred; wich is not correct.
Another thing you can try is, in the 3D software, to render the depth pass at twice the size, with the same anti-aliasing settings. This will result in more quality in your depth pass, but not so much difference in the result.
Enjoy!