DepthOfField Class
Namespace: Stride.Rendering.ImagesAssembly: 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
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 |
|
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 |
|
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. |
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
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
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
[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.
Methods
Destroy()
protected override void Destroy()
Overrides
DrawCore(RenderDrawContext)
protected override void DrawCore(RenderDrawContext context)
Parameters
Type | Name | Description |
---|---|---|
RenderDrawContext | context |
Overrides
InitializeCore()
protected override void InitializeCore()
Overrides
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()