UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DiaphragmDOF.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 PostProcessDOF.h: Post process Depth of Field implementation.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "RendererInterface.h"
12
13class FViewInfo;
17
18
19namespace DiaphragmDOF
20{
21
22// Whether DOF is enabled for the requested view.
23bool IsEnabled(const FViewInfo& View);
24
26
29{
30 // Size of the sensor, in unreal unit.
33
34 // Aspect ratio of the croped frame being rendered.
36
37 // Focal length of the lens in unreal unit.
39 // float HorizontalFocalLength = VerticalFocalLength / Squeeze;
40
41 // Apperture diameter in fstop
42 float FStops; // = VerticalFocalLength / ApartureDiameter.
43
44 // Unclamped background vertical coc radius, in horizontal ViewportUV unit.
46 // HorizontalInfinityBackgroundCocRadius = InfinityBackgroundCocRadius / Squeeze
47 // VerticalInfinityBackgroundCocRadius = InfinityBackgroundCocRadius
48
51
54
57
58 // Resolution less minimal foreground coc radius < 0.
60
61 // Resolution less maximal background coc radius.
63
64 // Focus distance in unreal unit.
66
67 // SqueezeFactor = VerticalFocalDistance / HorizontalFocalDistance
68 float Squeeze;
69
70 // Swirly bokeh Petzval lens effect
71 float Petzval;
77
78 static const uint32 MaxMatteBoxFlags = 3;
80
81 // The maximum radius of depth blur.
84
86 void Compile(const FViewInfo& View);
87
90
95 float DepthToResCocRadius(float SceneDepth, float HorizontalResolution) const;
96
99 {
100 // Dynamic CoC offset is designed to go to zero at infinite distance, so we don't need to factor it into the max background radius
102 }
103
112
113private:
115 float GetCocOffset(float CocRadius) const;
116};
117
118
119enum class EBokehShape
120{
121 // No blade simulation.
122 Circle,
123
124 // Diaphragm's blades are straight.
126
127 // Diaphragm's blades are circle with a radius matching largest aperture of the lens system settings.
129};
130
131
134{
135 // Shape of the bokeh.
137
138 // Scale factor to transform a CocRadius to CircumscribedRadius or in circle radius.
141
142 // Number of blades of the diaphragm.
144
145 // Rotation angle of the diaphragm in radians.
147
148 // BokehShape == RoundedBlades specific parameters.
149 struct
150 {
151 // Radius of the blade for a boked area=PI.
153
154 // Offset of the center of the blade's circle from the center of the bokeh.
157
158 float Squeeze;
159
161 void Compile(const FViewInfo& View, const FPhysicalCocModel& CocModel);
162
163 bool operator==(const FBokehModel& Other) const
164 {
165 return BokehShape == Other.BokehShape
166 && CocRadiusToCircumscribedRadius == Other.CocRadiusToCircumscribedRadius
167 && CocRadiusToIncircleRadius == Other.CocRadiusToIncircleRadius
168 && DiaphragmBladeCount == Other.DiaphragmBladeCount
169 && DiaphragmRotation == Other.DiaphragmRotation
170 && RoundedBlades.DiaphragmBladeRadius == Other.RoundedBlades.DiaphragmBladeRadius
171 && RoundedBlades.DiaphragmBladeCenterOffset == Other.RoundedBlades.DiaphragmBladeCenterOffset
172 && Squeeze == Other.Squeeze;
173 }
174
175 bool operator!=(const FBokehModel& Other) const
176 {
177 return !(*this == Other);
178 }
179};
180
182RENDERER_API bool IsSupported(const FStaticShaderPlatform ShaderPlatform);
183
186 FRDGBuilder& GraphBuilder,
187 const FSceneTextureParameters& SceneTextures,
188 const FViewInfo& View,
192
193
197 SHADER_PARAMETER_RDG_TEXTURE(Texture2D, DynamicRadiusOffsetLUT)
205 SHADER_PARAMETER(float, DepthBlurExponent)
207
209 FRDGBuilder& GraphBuilder,
211 const FPhysicalCocModel& CocModel,
212 float CocRadiusBasis = 1.0f);
213
214} // namespace DiaphragmDOF
215
#define FORCEINLINE
Definition AndroidPlatform.h:140
float GNearClippingPlane
Definition CoreGlobals.cpp:260
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define SHADER_PARAMETER_RDG_TEXTURE(ShaderType, MemberName)
Definition ShaderParameterMacros.h:1752
#define SHADER_PARAMETER_SAMPLER(ShaderType, MemberName)
Definition ShaderParameterMacros.h:1740
#define BEGIN_SHADER_PARAMETER_STRUCT(StructTypeName, DllStorage)
Definition ShaderParameterMacros.h:1482
#define END_SHADER_PARAMETER_STRUCT()
Definition ShaderParameterMacros.h:1485
#define SHADER_PARAMETER(MemberType, MemberName)
Definition ShaderParameterMacros.h:1684
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition RenderGraphBuilder.h:49
Definition RenderGraphResources.h:571
Definition RHIResources.h:2153
Definition SceneRendering.h:1132
Definition StaticArray.h:26
Definition DiaphragmDOF.cpp:698
RENDERER_API bool AddPasses(FRDGBuilder &GraphBuilder, const FSceneTextureParameters &SceneTextures, const FViewInfo &View, FRDGTextureRef InputSceneColor, const FTranslucencyPassResources &TranslucencyViewResources, FRDGTextureRef &OutputColor)
Definition DiaphragmDOF.cpp:1486
FVector4f CircleDofHalfCoc(const FViewInfo &View)
Definition DiaphragmDOFUtils.cpp:49
void SetCocModelParameters(FRDGBuilder &GraphBuilder, FDOFCocModelShaderParameters *OutParameters, const FPhysicalCocModel &CocModel, float CocRadiusBasis)
Definition DiaphragmDOF.cpp:699
EBokehShape
Definition DiaphragmDOF.h:120
bool IsEnabled(const FViewInfo &View)
Definition DiaphragmDOF.cpp:1471
RENDERER_API bool IsSupported(const FStaticShaderPlatform ShaderPlatform)
Definition DiaphragmDOF.cpp:177
Definition DiaphragmDOF.h:134
int32 DiaphragmBladeCount
Definition DiaphragmDOF.h:143
bool operator==(const FBokehModel &Other) const
Definition DiaphragmDOF.h:163
bool operator!=(const FBokehModel &Other) const
Definition DiaphragmDOF.h:175
float CocRadiusToIncircleRadius
Definition DiaphragmDOF.h:140
float DiaphragmBladeRadius
Definition DiaphragmDOF.h:152
EBokehShape BokehShape
Definition DiaphragmDOF.h:136
float Squeeze
Definition DiaphragmDOF.h:158
float DiaphragmBladeCenterOffset
Definition DiaphragmDOF.h:155
struct DiaphragmDOF::FBokehModel::@1788 RoundedBlades
float DiaphragmRotation
Definition DiaphragmDOF.h:146
float CocRadiusToCircumscribedRadius
Definition DiaphragmDOF.h:139
Definition DiaphragmDOF.h:29
float BarrelRadius
Definition DiaphragmDOF.h:75
FVector2f PetzvalExclusionBoxExtents
Definition DiaphragmDOF.h:73
TStaticArray< FMatteBoxFlag, MaxMatteBoxFlags > MatteBoxFlags
Definition DiaphragmDOF.h:79
FORCEINLINE float ComputeViewMinForegroundCocRadius(float HorizontalResolution) const
Definition DiaphragmDOF.h:108
float MaxBackgroundCocRadius
Definition DiaphragmDOF.h:62
static const uint32 MaxMatteBoxFlags
Definition DiaphragmDOF.h:78
float MaxDepthBlurRadius
Definition DiaphragmDOF.h:82
FORCEINLINE float ComputeViewMaxBackgroundCocRadius(float HorizontalResolution) const
Definition DiaphragmDOF.h:98
float DepthToResCocRadius(float SceneDepth, float HorizontalResolution) const
Definition DiaphragmDOFUtils.cpp:211
float RenderingAspectRatio
Definition DiaphragmDOF.h:35
float InfinityBackgroundCocRadius
Definition DiaphragmDOF.h:45
float FStops
Definition DiaphragmDOF.h:42
FRHITexture * DynamicRadiusOffsetLUT
Definition DiaphragmDOF.h:56
float VerticalFocalLength
Definition DiaphragmDOF.h:38
float Petzval
Definition DiaphragmDOF.h:71
float SensorHeight
Definition DiaphragmDOF.h:32
float DepthBlurExponent
Definition DiaphragmDOF.h:83
FVector2f GetLensRadius() const
Definition DiaphragmDOFUtils.cpp:201
float BarrelLength
Definition DiaphragmDOF.h:76
float InFocusRadius
Definition DiaphragmDOF.h:53
float Squeeze
Definition DiaphragmDOF.h:68
float SensorWidth
Definition DiaphragmDOF.h:31
float PetzvalFalloffPower
Definition DiaphragmDOF.h:72
float PetzvalExclusionBoxRadius
Definition DiaphragmDOF.h:74
float FocusDistance
Definition DiaphragmDOF.h:65
float MinForegroundCocRadius
Definition DiaphragmDOF.h:59
bool bEnableDynamicOffset
Definition DiaphragmDOF.h:50
Definition AndroidStaticShaderPlatform.inl:18
Definition SceneRendering.h:840
Definition TranslucentPassResource.h:28