Depth of Field (Deprecated) is a common postprocessing effect that simulates the properties of a camera lens. The name refers to the fact that the effect was added in Unity 3.4, but now is superseded by a more modern Depth Of Field effect which uses optimized techniques to simulate lens blurs and enables better transitions between focal areas. However, depending on the use case, performance might be a lot better in the old 3.4 version as it was developed for older hardware.
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.
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, you must have the Standard Assets Effects package installed before it becomes available.
Property: | Function: |
---|---|
General Settings | |
Resolution | Determines the internal render target sizes. A lower resolution will result in faster rendering and lower memory requirements. |
Quality | The quality level. Choose between the faster OnlyBackground or the higher-quality BackgroundAndForeground which calculates the depth-of-field defocus for both areas separately. |
Simple tweak | Switches to a simpler focal model. |
Visualize focus | This shows the focal plane in the game view to assist learning and debugging. |
Enable bokeh | This will generate more realistic lens blurs where very bright parts are scaled and overlap. |
Focal Settings | |
Focal distance | The distance to the focal plane from the camera position in world space. |
Object Focus | Determine the focal distance using a target object in the scene. |
Smoothness | The smoothness when transitioning from out-of-focus to in-focus areas. |
Focal size | The size of the in-focus area. |
Blur | |
Blurriness | How many iterations are used when blurring the various buffers (each iteration requires processing time). |
Blur spread | The blur radius. This is resolution-independent, so you may need to readjust the value for each required resolution. |
Bokeh Settings | |
Destination | Enabling foreground and background blur increases rendering time but gives more realistic results. |
Intensity | Blend intensity used as bokeh shapes are being accumulated. This is a critical value that always needs to be carefully adjusted. |
Min luminance | The luminance threshold below which pixels will not have bokeh artifacts applied. |
Min contrast | The 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. |
Downsample | The size of the internal render target used for accumulating bokeh shapes. |
Size | The maximum bokeh size. Will be modulated by the amount of defocus (Circle of Confusion). |
Bokeh Texture | The 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.
This effect requires a graphics card that supports Shader Model 3 and depth textures. See the Graphics Hardware Capabilities and Emulation page for further details and a list of compliant hardware.
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.