Depth of Field is a common postprocessing effect that simulates the properties of a camera lens. This version is a more modern and sophisticated version of the old Depth of Field (Deprecated) effect that works especially well with HDR rendering and a DirectX 11 compatible graphics device.
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. Common Bokeh shapes are discs, hexagons and other shapes of higher level dihedral groups.
While the regular version only supports disc shapes (generated via circular texture sampling), the DX11/GL4 version is able to splat any shape as defined by the Bokeh Texture.
An example of Depth of Field effect can be seen in the following image, displaying the results of a focused foreground and a defocused background..
As with the other image effects, you must have the Standard Assets Effects package installed before it becomes available.
Property: | Function: |
---|---|
Focal Settings | |
Visualize | Overlay color indicating camera focus. |
Focal distance | The distance to the focal plane from the camera position in world space. |
Focal Size | Increase the total focal area. |
Focus on Transform | Determine the focal distance using a target object in the scene. |
Aperture | The camera’s aperture defining the transition between focused and defocused areas. It is good practice to keep this value as high as possible, as otherwise sampling artifacts might occur, especially when the Max Blur Distance is big. Bigger Aperture values will automatically downsample the image to produce a better defocus. |
Defocus Type | Algorithm used to produce defocused areas. DX11 is effectively a bokeh splatting technique while DiscBlur indicates a more traditional (scatter as gather) based blur. |
Sample Count | Amount of filter taps. Greatly affects performance. |
Max Blur Distance | Max distance for filter taps. Affects texture cache and can cause undersampling artifacts if value is too big. A value smaller than 4.0 should produce decent results. |
High Resolution | Perform defocus operations in full resolution. Affects performance but might help reduce unwanted artifacts and produce more defined bokeh shapes. |
Near Blur | Foreground areas will overlap at a performance cost. |
Overlap Size | Increase foreground overlap dilation if needed. |
DX11 Bokeh Settings | |
Bokeh Texture | Texture defining bokeh shape. |
Bokeh Scale | Size of bokeh texture. |
Bokeh Intensity | Blend strength of bokeh shapes. |
Min Luminance | Only pixels brighter than this value will cast bokeh shapes. Affects performance as it limits overdraw to a more reasonable amount. |
Spawn Heuristic | Bokeh shapes will only be cast if pixel in questions passes a frequency check. A threshold around 0.1 seems like a good tradeoff between performance and quality. |
This powerful technique enables proper Scattering, however due to high demands on fillrate, it should be used with care. The parameters Spawn Heuristic and Min Luminance control when and where Bokeh Sprites will be placed. If pixels don’t pass a luminance and frequency check, a simple Box Blur will be used instead. It’s however hard to notice as it uses the same kernel width as the Bokeh sprites.
The following pictures show that the road, that is neither bright nor bears great frequency changes can just be blurred with a simple box filter without ruining the overall Bokeh experience.
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.