Depth of Field 3.4
Manual     Reference     Scripting   
Reference Manual > Image Effect Scripts > Depth of Field 3.4

Depth of Field 3.4

Depth of Field 3.4 is a common postprocessing effect that simulates the properties of a camera lens. The name refers to the fact that the effect has had significant performance and feature improvements in Unity 3.4.

In real life, a camera can only focus sharply on an object at a specific distance; objects nearer or farther from the camera will be somewhat out of focus. The blurring not only gives a visual cue about an object's distance but also introduces bokeh which is the term for pleasing visual artifacts that appear around bright areas of the image as they fall out of focus.

An example of the new Depth of Field effect can be seen in the following images, displaying the results of a defocused foreground and a defocused background. Notice how the foreground blur overlaps with the rest while the background doesn't.


Only the nearby pipes are in the focal area

Foreground vs Background blurring with Depth of Field

You might also consider using the Tilt Shift effect for a more straightforward but less sophisticated depth-of-field effect.

As with the other image effects, this effect is only available in Unity Pro and you must have the Pro Standard Assets installed before it becomes available.

Properties

General Settings
ResolutionDetermines the internal render target sizes. A lower resolution will result in faster rendering and lower memory requirements.
QualityThe quality level. Choose between the faster OnlyBackground or the higher-quality BackgroundAndForeground which calculates the depth-of-field defocus for both areas separately.
Simple tweakSwitches to a simpler focal model.
Visualize focusThis shows the focal plane in the game view to assist learning and debugging.
Enable bokehThis will generate more realistic lens blurs where very bright parts are scaled and overlap.
Focal Settings
Focal distanceThe distance to the focal plane from the camera position in world space.
Object FocusDetermine the focal distance using a target object in the scene.
SmoothnessThe smoothness when transitioning from out-of-focus to in-focus areas.
Focal sizeThe size of the in-focus area.
Blur
BlurrinessHow many iterations are used when blurring the various buffers (each iteration requires processing time).
Blur spreadThe blur radius. This is resolution-independent, so you may need to readjust the value for each required resolution.
Bokeh Settings
DestinationEnabling foreground and background blur increases rendering time but gives more realistic results.
IntensityBlend intensity used as bokeh shapes are being accumulated. This is a critical value that always needs to be carefully adjusted.
Min luminanceThe luminance threshold below which pixels will not have bokeh artifacts applied.
Min contrastThe contrast threshold below which pixels will not have bokeh artifacts applied. The significance of this is that you usually only need bokeh shapes in areas of high frequency (ie, cluttered or "noisy" areas of image) since they are otherwise nearly invisible. Performance will be improved if you use this parameter to avoid generating unnecessary bokeh artifacts.
DownsampleThe size of the internal render target used for accumulating bokeh shapes.
SizeThe maximum bokeh size. Will be modulated by the amount of defocus (Circle of Confusion).
Bokeh TextureThe texture defining the bokeh shapes.

Note that since the bokeh effect is created by drawing triangles per pixel, it can drastically affect your framerate, especially if it's not adjusted optimally. Adjust the Size, Min luminance, Min contrast, Downsample and Resolution to improve performance. Also, since the screen is darkened before the bokeh shapes are applied, you should use an appropriate Blurriness level to remove possible artefacts.

Hardware support

This effect requires a graphics card with pixel shaders (3.0) or OpenGL ES 2.0. Additionally, depth texture support is required. PC: NVIDIA cards since 2004 (GeForce 6), AMD cards since 2005 (Radeon X1300), Intel cards since 2006 (GMA X3000); Mobile: OpenGL ES 2.0 with depth texture support; Consoles: Xbox 360, PS3.

All image effects automatically disable themselves when they can not run on end-users graphics card.

Page last updated: 2011-09-19