docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class DepthOfField

    A volume component that holds settings for the Depth Of Field effect.

    Inheritance
    object
    Object
    ScriptableObject
    VolumeComponent
    DepthOfField
    Implements
    IApplyRevertPropertyContextMenuItemProvider
    IPostProcessComponent
    Inherited Members
    VolumeComponent.active
    VolumeComponent.Override(VolumeComponent, float)
    VolumeComponent.SetAllOverridesTo(bool)
    VolumeComponent.GetHashCode()
    VolumeComponent.AnyPropertiesIsOverridden()
    VolumeComponent.Release()
    VolumeComponent.TryGetRevertMethodForFieldName(SerializedProperty, out Action<SerializedProperty>)
    VolumeComponent.GetSourceTerm()
    VolumeComponent.TryGetApplyMethodForFieldName(SerializedProperty, out Action<SerializedProperty>)
    VolumeComponent.GetSourceName(Component)
    VolumeComponent.displayName
    VolumeComponent.parameters
    ScriptableObject.CreateInstance(string)
    ScriptableObject.CreateInstance(Type)
    ScriptableObject.CreateInstance<T>()
    Object.GetEntityId()
    Object.GetInstanceID()
    Object.Equals(object)
    Object.InstantiateAsync<T>(T)
    Object.InstantiateAsync<T>(T, Transform)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)
    Object.InstantiateAsync<T>(T, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, InstantiateParameters, CancellationToken)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate<T>(T, InstantiateParameters)
    Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: UnityEngine.Rendering.Universal
    Assembly: Unity.RenderPipelines.Universal.Runtime.dll
    Syntax
    [Serializable]
    [VolumeComponentMenu("Post-processing/Depth Of Field")]
    [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
    public sealed class DepthOfField : VolumeComponent, IApplyRevertPropertyContextMenuItemProvider, IPostProcessComponent
    Remarks

    You can add VolumeComponent to a VolumeProfile in the Editor to apply a Depth Of Field post-processing effect.

    Examples

    This sample code shows how settings can be retrieved and modified in runtime:

    using System;
    using UnityEngine;
    using UnityEngine.Rendering;
    using UnityEngine.Rendering.Universal;
    

    public class ModifyVolumeComponent : MonoBehaviour { [SerializeField] VolumeProfile volumeProfile; [SerializeField] VolumeSettings volumeSettings;

    private bool m_HasRetrievedVolumeComponent;
    private DepthOfField m_VolumeComponent;
    
    [Serializable]
    private struct VolumeSettings
    {
        public bool active;
        public DepthOfFieldModeParameter mode;
        public MinFloatParameter gaussianStart;
        public MinFloatParameter gaussianEnd;
        public ClampedFloatParameter gaussianMaxRadius;
        public BoolParameter highQualitySampling;
        public MinFloatParameter focusDistance;
        public ClampedFloatParameter aperture;
        public ClampedFloatParameter focalLength;
        public ClampedIntParameter bladeCount;
        public ClampedFloatParameter bladeCurvature;
        public ClampedFloatParameter bladeRotation;
    
    
        public void SetVolumeComponentSettings(ref DepthOfField volumeComponent)
        {
            volumeComponent.active = active;
            volumeComponent.mode = mode;
            volumeComponent.gaussianStart = gaussianStart;
            volumeComponent.gaussianEnd = gaussianEnd;
            volumeComponent.gaussianMaxRadius = gaussianMaxRadius;
            volumeComponent.highQualitySampling = highQualitySampling;
            volumeComponent.focusDistance = focusDistance;
            volumeComponent.aperture = aperture;
            volumeComponent.focalLength = focalLength;
            volumeComponent.bladeCount = bladeCount;
            volumeComponent.bladeCurvature = bladeCurvature;
            volumeComponent.bladeRotation = bladeRotation;
        }
    
        public void GetVolumeComponentSettings(ref DepthOfField volumeComponent)
        {
            active = volumeComponent.active;
            mode = volumeComponent.mode;
            gaussianStart = volumeComponent.gaussianStart;
            gaussianEnd = volumeComponent.gaussianEnd;
            gaussianMaxRadius = volumeComponent.gaussianMaxRadius;
            highQualitySampling = volumeComponent.highQualitySampling;
            focusDistance = volumeComponent.focusDistance;
            aperture = volumeComponent.aperture;
            focalLength = volumeComponent.focalLength;
            bladeCount = volumeComponent.bladeCount;
            bladeCurvature = volumeComponent.bladeCurvature;
            bladeRotation = volumeComponent.bladeRotation;
        }
    }
    
    private void Start()
    {
        m_HasRetrievedVolumeComponent = GetVolumeComponent(in volumeProfile, ref m_VolumeComponent);
        if (m_HasRetrievedVolumeComponent)
            volumeSettings.GetVolumeComponentSettings(ref m_VolumeComponent);
    }
    
    private void Update()
    {
        if (!m_HasRetrievedVolumeComponent)
            return;
    
        volumeSettings.SetVolumeComponentSettings(ref m_VolumeComponent);
    }
    
    private static bool GetVolumeComponent(in VolumeProfile volumeProfile, ref DepthOfField volumeComponent)
    {
        if (volumeComponent != null)
            return true;
    
        if (volumeProfile == null)
        {
            Debug.LogError("ModifyVolumeComponent.GetVolumeComponent():\nvolumeProfile has not been assigned.");
            return false;
        }
    
        volumeProfile.TryGet(out DepthOfField component);
        if (component == null)
        {
            Debug.LogError($"ModifyVolumeComponent.GetVolumeComponent():\nMissing component in the \"{volumeProfile.name}\" VolumeProfile ");
            return false;
        }
    
        volumeComponent = component;
        return true;
    }
    

    }

    Fields

    aperture

    The ratio of aperture (known as f-stop or f-number). The smaller the value is, the shallower the depth of field is.

    Declaration
    [Tooltip("The ratio of aperture (known as f-stop or f-number). The smaller the value is, the shallower the depth of field is.")]
    public ClampedFloatParameter aperture
    Field Value
    Type Description
    ClampedFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    bladeCount

    The number of aperture blades.

    Declaration
    [Tooltip("The number of aperture blades.")]
    public ClampedIntParameter bladeCount
    Field Value
    Type Description
    ClampedIntParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    bladeCurvature

    The curvature of aperture blades. The smaller the value is, the more visible aperture blades are. A value of 1 will make the bokeh perfectly circular.

    Declaration
    [Tooltip("The curvature of aperture blades. The smaller the value is, the more visible aperture blades are. A value of 1 will make the bokeh perfectly circular.")]
    public ClampedFloatParameter bladeCurvature
    Field Value
    Type Description
    ClampedFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    bladeRotation

    The rotation of aperture blades in degrees.

    Declaration
    [Tooltip("The rotation of aperture blades in degrees.")]
    public ClampedFloatParameter bladeRotation
    Field Value
    Type Description
    ClampedFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    focalLength

    The distance between the lens and the film. The larger the value is, the shallower the depth of field is.

    Declaration
    [Tooltip("The distance between the lens and the film. The larger the value is, the shallower the depth of field is.")]
    public ClampedFloatParameter focalLength
    Field Value
    Type Description
    ClampedFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    focusDistance

    The distance to the point of focus.

    Declaration
    [Tooltip("The distance to the point of focus.")]
    public MinFloatParameter focusDistance
    Field Value
    Type Description
    MinFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    gaussianEnd

    The distance at which the blurring will reach its maximum radius.

    Declaration
    [Tooltip("The distance at which the blurring will reach its maximum radius.")]
    public MinFloatParameter gaussianEnd
    Field Value
    Type Description
    MinFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    gaussianMaxRadius

    The maximum radius of the gaussian blur. Values above 1 may show under-sampling artifacts.

    Declaration
    [Tooltip("The maximum radius of the gaussian blur. Values above 1 may show under-sampling artifacts.")]
    public ClampedFloatParameter gaussianMaxRadius
    Field Value
    Type Description
    ClampedFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    gaussianStart

    The distance at which the blurring will start.

    Declaration
    [Tooltip("The distance at which the blurring will start.")]
    public MinFloatParameter gaussianStart
    Field Value
    Type Description
    MinFloatParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    highQualitySampling

    Use higher quality sampling to reduce flickering and improve the overall blur smoothness.

    Declaration
    [Tooltip("Use higher quality sampling to reduce flickering and improve the overall blur smoothness.")]
    public BoolParameter highQualitySampling
    Field Value
    Type Description
    BoolParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    mode

    Use this to select Focusing modes for the depth of field effect.

    Declaration
    [Tooltip("Use \"Gaussian\" for a faster but non physical depth of field; \"Bokeh\" for a more realistic but slower depth of field.")]
    public DepthOfFieldModeParameter mode
    Field Value
    Type Description
    DepthOfFieldModeParameter
    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    Methods

    IsActive()

    Tells if the post process needs to be rendered or not.

    Declaration
    public bool IsActive()
    Returns
    Type Description
    bool

    true if the effect should be rendered, false otherwise.

    See Also
    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter

    Implements

    IApplyRevertPropertyContextMenuItemProvider
    IPostProcessComponent

    See Also

    VolumeProfile
    VolumeComponent
    IPostProcessComponent
    VolumeParameter<T>
    DepthOfFieldModeParameter
    MinFloatParameter
    ClampedFloatParameter
    BoolParameter
    ClampedIntParameter
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)