Table of Contents

Class DepthOfField

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.

[DataContract("DepthOfField")]
public sealed class DepthOfField : ImageEffect, IComponent, IReferencable, ICollectorHolder, IImageEffect, IGraphicsRenderer, IGraphicsRendererBase, IGraphicsRendererCore, IDisposable
Inheritance
DepthOfField
Implements
Inherited Members
Extension Methods

Constructors

DepthOfField()

Initializes a new instance of the DepthOfField class.

public DepthOfField()

Properties

AutoFocus

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

[DataMember(50)]
public bool AutoFocus { get; set; }

Property Value

bool

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

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

float[]

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

int[]

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.009999999776482582, 1, 0.009999999776482582, 0.10000000149011612, 2)]
[Display("Size", null)]
public float MaxBokehSize { get; set; }

Property Value

float

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.009999999776482582, 0.10000000149011612, 2)]
public float QualityPreset { get; set; }

Property Value

float

Technique

Bokeh technique used to blur each level.

[DataMember(40)]
public BokehTechnique Technique { get; set; }

Property Value

BokehTechnique

Remarks

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

Methods

Destroy()

Disposes of object resources.

protected override void Destroy()

DrawCore(RenderDrawContext)

Main drawing method for this renderer that must be implemented.

protected override void DrawCore(RenderDrawContext context)

Parameters

context RenderDrawContext

The context.

InitializeCore()

protected override void 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

colorBuffer Texture

A color buffer to process.

depthBuffer Texture

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()