Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    DepthOfField Class

    Namespace: Stride.Rendering.Images
    Assembly: Stride.Rendering.dll

    Applies a depth-of-field effect to a scene. It takes as input a color-buffer where the scene was rendered, with its associated depth-buffer. You also need to provide the camera configuration you used when rendering the scene. You can optionally specify which bokeh technique should be used, the number of LOD levels with their Circle-of-Confusion strengths and their resolution.

    System.Object → DisposeBase → ComponentBase → RendererCoreBase → RendererBase → DrawEffect → ImageEffect → DepthOfField
    Derived from DepthOfField:

    [DataContract("DepthOfField")]
    public sealed class DepthOfField : ImageEffect, IComponent, IReferencable, ICollectorHolder, IImageEffect, IGraphicsRenderer, IGraphicsRendererBase, IGraphicsRendererCore, IDisposable
    Name Description
    Constructors
    DepthOfField()

    Initializes a new instance of the DepthOfField class.

    Properties
    AutoFocus

    Auto-focus on the pixel at the center of the screen.

    DOFAreas

    Areas of the depth of field: [nearStart, nearEnd, farStart, farEnd] expressed as a distance from the camera.

    LevelCoCValues

    The number of layers with their own CoC strength. Note that you need to define at least 1 level of blur, each level of blur should have a CoC stronger than its predecessor and the last level should always have a CoC of 1.0. Example: { 0.25f, 0.5f, 1.0f } The higher the number of levels is, the smoother the transition between 2 levels is, but at a performance cost.

    LevelDownscaleFactors

    For each level defined in you can define a downscale factor (a power of 2) at which to operate. When not specified, the levels are treated by default at half the resolution of the original image. Example: for { 1, 2 }, the first level will be processed at half the original resolution, and the second level at 1/4. The array provided must be of the same size as the array.

    MaxBokehSize

    Maximum size of the bokeh (ie. when the circle of confusion is 1.0). This is resolution-independent, it is a ratio proportional to the screen width in percentage.

    QualityPreset

    Affects a preset quality setting, between 0 (lowest quality) and 1 (highest quality). This auto-configures and .

    Technique

    Bokeh technique used to blur each level.

    Methods
    Destroy()
    DrawCore(RenderDrawContext)
    InitializeCore()
    SetColorDepthInput(Texture, Texture)

    Provides a color buffer and a depth buffer to apply the depth-of-field to.

    SetupTechnique()

    Caches the current configuration and re-generates the filter effect of each LOD level to avoid generating garbage a each frame.

    | Improve this Doc View Source

    Constructors


    DepthOfField()

    Initializes a new instance of the DepthOfField class.

    public DepthOfField()
    | Improve this Doc View Source

    Properties


    AutoFocus

    Auto-focus on the pixel at the center of the screen.

    [DataMember(50)]
    public bool AutoFocus { get; set; }
    Property Value
    Type Description
    System.Boolean

    DOFAreas

    Areas of the depth of field: [nearStart, nearEnd, farStart, farEnd] expressed as a distance from the camera.

    [DataMember(20)]
    public Vector4 DOFAreas { get; set; }
    Property Value
    Type Description
    Vector4

    LevelCoCValues

    The number of layers with their own CoC strength. Note that you need to define at least 1 level of blur, each level of blur should have a CoC stronger than its predecessor and the last level should always have a CoC of 1.0. Example: { 0.25f, 0.5f, 1.0f } The higher the number of levels is, the smoother the transition between 2 levels is, but at a performance cost.

    public float[] LevelCoCValues { get; set; }
    Property Value
    Type Description
    System.Single[]

    LevelDownscaleFactors

    For each level defined in you can define a downscale factor (a power of 2) at which to operate. When not specified, the levels are treated by default at half the resolution of the original image. Example: for { 1, 2 }, the first level will be processed at half the original resolution, and the second level at 1/4. The array provided must be of the same size as the array.

    public int[] LevelDownscaleFactors { get; set; }
    Property Value
    Type Description
    System.Int32[]

    MaxBokehSize

    Maximum size of the bokeh (ie. when the circle of confusion is 1.0). This is resolution-independent, it is a ratio proportional to the screen width in percentage.

    [DataMember(10)]
    [DataMemberRange(0.0099999997764825821, 1, 0.0099999997764825821, 0.10000000149011612, 2)]
    [Display("Size", null)]
    public float MaxBokehSize { get; set; }
    Property Value
    Type Description
    System.Single
    Remarks

    This property is not supposed to be modified at each frame since it generates garbage. Instead you should set it once for your scene and play with the DOF areas / lens parameters to make out-of-focus objects create bigger bokeh shapes.


    QualityPreset

    Affects a preset quality setting, between 0 (lowest quality) and 1 (highest quality). This auto-configures and .

    [DataMember(30)]
    [DataMemberRange(0, 1, 0.0099999997764825821, 0.10000000149011612, 2)]
    public float QualityPreset { get; set; }
    Property Value
    Type Description
    System.Single

    Technique

    Bokeh technique used to blur each level.

    [DataMember(40)]
    public BokehTechnique Technique { get; set; }
    Property Value
    Type Description
    BokehTechnique
    Remarks

    This influences the bokeh shape (circular, hexagonal...) as well as the performance.

    | Improve this Doc View Source

    Methods


    Destroy()

    protected override void Destroy()
    Overrides
    RendererCoreBase.Destroy()

    DrawCore(RenderDrawContext)

    protected override void DrawCore(RenderDrawContext context)
    Parameters
    Type Name Description
    RenderDrawContext context
    Overrides
    RendererBase.DrawCore(RenderDrawContext)

    InitializeCore()

    protected override void InitializeCore()
    Overrides
    RendererCoreBase.InitializeCore()

    SetColorDepthInput(Texture, Texture)

    Provides a color buffer and a depth buffer to apply the depth-of-field to.

    public void SetColorDepthInput(Texture colorBuffer, Texture depthBuffer)
    Parameters
    Type Name Description
    Texture colorBuffer

    A color buffer to process.

    Texture depthBuffer

    The depth buffer corresponding to the color buffer provided.


    SetupTechnique()

    Caches the current configuration and re-generates the filter effect of each LOD level to avoid generating garbage a each frame.

    public void SetupTechnique()

    Inherited Members

    ImageEffect.EnableSetRenderTargets
    ImageEffect.SetInput(Int32, Texture)
    ImageEffect.Reset()
    ImageEffect.SetOutput(Texture)
    ImageEffect.SetOutput(Texture[])
    ImageEffect.SetDepthOutput(Texture, Texture)
    ImageEffect.SetDepthOutput(Texture, Texture[])
    ImageEffect.SetViewport(Nullable<Viewport>)
    ImageEffect.PreDrawCore(RenderDrawContext)
    ImageEffect.SetRenderTargets(RenderDrawContext)
    ImageEffect.PostDrawCore(RenderDrawContext)
    ImageEffect.DisposeCreatedRenderTargetViews(RenderDrawContext)
    ImageEffect.InputCount
    ImageEffect.GetInput(Int32)
    ImageEffect.GetSafeInput(Int32)
    ImageEffect.DepthStencil
    ImageEffect.HasDepthStencilOutput
    ImageEffect.OutputCount
    ImageEffect.GetOutput(Int32)
    ImageEffect.GetSafeOutput(Int32)
    ImageEffect.NewScopedRenderTarget2D(TextureDescription)
    ImageEffect.NewScopedRenderTarget2D(Int32, Int32, PixelFormat, TextureFlags, Int32)
    ImageEffect.NewScopedRenderTarget2D(Int32, Int32, PixelFormat, MipMapCount, TextureFlags, Int32)
    DrawEffect.SamplingPattern
    DrawEffect.Parameters
    DrawEffect.Scaler
    DrawEffect.SetDefaultParameters()
    DrawEffect.Draw(RenderDrawContext, String)
    DrawEffect.Draw(RenderDrawContext, String, Object[])
    DrawEffect.ToString()
    RendererBase.Draw(RenderDrawContext)
    RendererCoreBase.Enabled
    RendererCoreBase.Profiling
    RendererCoreBase.ProfilingKey
    RendererCoreBase.Context
    RendererCoreBase.Services
    RendererCoreBase.Content
    RendererCoreBase.GraphicsDevice
    RendererCoreBase.EffectSystem
    RendererCoreBase.Initialized
    RendererCoreBase.Initialize(RenderContext)
    RendererCoreBase.Unload()
    RendererCoreBase.NewScopedBuffer(BufferDescription, PixelFormat)
    RendererCoreBase.NewScopedTypedBuffer(Int32, PixelFormat, Boolean, GraphicsResourceUsage)
    RendererCoreBase.PushScopedResource<T>(T)
    RendererCoreBase.CheckIsInDrawCore()
    RendererCoreBase.ToLoadAndUnload<T>(T)
    RendererCoreBase.PreDrawCoreInternal(RenderDrawContext)
    RendererCoreBase.EnsureContext(RenderContext)
    RendererCoreBase.PostDrawCoreInternal(RenderDrawContext)
    ComponentBase.Tags
    ComponentBase.Name
    ComponentBase.ICollectorHolder.Collector
    ComponentBase.OnNameChanged()
    DisposeBase.Dispose()
    DisposeBase.IsDisposed
    DisposeBase.IReferencable.ReferenceCount
    DisposeBase.IReferencable.AddReference()
    DisposeBase.IReferencable.Release()
    DisposeBase.OnAddReference()
    DisposeBase.OnReleaseReference()

    Extension Methods

    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    ImageEffectExtensions.SetInput(IImageEffect, Texture)
    ImageEffectExtensions.SetInput(IImageEffect, Texture, Texture)
    ImageEffectExtensions.SetInput(IImageEffect, Texture, Texture, Texture)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation