UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DepthRendering.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 DepthRendering.h: Depth rendering definitions.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "RHI.h"
11#include "HitProxies.h"
12#include "ShaderBaseClasses.h"
13#include "MeshPassProcessor.h"
14
16class FScene;
18class FViewInfo;
19
21{
22 // tested at a higher level
24 // Opaque materials only
26 // Opaque and masked materials, but no objects with bUseAsOccluder disabled
28 // Full prepass, every object must be drawn and every pixel must match the base pass depth
30 // Masked materials only
32 // Full prepass, every object must be drawn and every pixel must match the base pass depth, except dynamic geometry which will render in the Velocity pass
34};
35
37
55
57
58void AddDitheredStencilFillPass(FRDGBuilder& GraphBuilder, TConstArrayView<FViewInfo> Views, FRDGTextureRef DepthTexture, const FDepthPassInfo& DepthPass);
59void AddDitheredStencilClearPass(FRDGBuilder& GraphBuilder, FRDGTextureRef DepthTexture, EShaderPlatform ShaderPlatform, bool bClearAllStencilBits);
60
62
66template <bool bUsePositionOnlyStream>
68{
70protected:
71
73
77
78public:
79
81 {
82 // Only the local vertex factory supports the position-only stream
84 {
86 }
87
89 {
91 }
92
93 // Only compile for the default material and masked materials
94 return (
99 }
100
105
107 const FScene* Scene,
108 ERHIFeatureLevel::Type FeatureLevel,
109 const FPrimitiveSceneProxy* PrimitiveSceneProxy,
110 const FMaterialRenderProxy& MaterialRenderProxy,
111 const FMaterial& Material,
113 FMeshDrawSingleShaderBindings& ShaderBindings) const
114 {
115 FMeshMaterialShader::GetShaderBindings(Scene, FeatureLevel, PrimitiveSceneProxy, MaterialRenderProxy, Material, ShaderElementData, ShaderBindings);
116 }
117};
118
123{
125public:
127 {
129 {
131 }
132
133 return
134 // Compile for materials that are masked
137 }
138
143
145 {
147
148 OutEnvironment.SetDefine(TEXT("ALLOW_DEBUG_VIEW_MODES"), AllowDebugViewmodes(Parameters.Platform));
149
150 // Regular opaque materials do not support scene textures, but SLW does support reading custom depth/stencil,
151 // so we need to make an exception here for the water depth prepass.
153 OutEnvironment.SetDefine(TEXT("SCENE_TEXTURES_DISABLED"), bIsSingleLayerWater ? 0u : 1u);
154 }
155
157
159 const FScene* Scene,
160 ERHIFeatureLevel::Type FeatureLevel,
161 const FPrimitiveSceneProxy* PrimitiveSceneProxy,
162 const FMaterialRenderProxy& MaterialRenderProxy,
163 const FMaterial& Material,
165 FMeshDrawSingleShaderBindings& ShaderBindings) const
166 {
167 FMeshMaterialShader::GetShaderBindings(Scene, FeatureLevel, PrimitiveSceneProxy, MaterialRenderProxy, Material, ShaderElementData, ShaderBindings);
168 }
169};
170
171template <bool bPositionOnly>
173 const FMaterial& Material,
174 const FVertexFactoryType* VertexFactoryType,
175 ERHIFeatureLevel::Type FeatureLevel,
179 FShaderPipelineRef& ShaderPipeline);
180
181class FDepthPassMeshProcessor : public FSceneRenderingAllocatorObject<FDepthPassMeshProcessor>, public FMeshPassProcessor
182{
183public:
184
187 const FScene* Scene,
193 const bool InbEarlyZPassMovable,
195 const bool bDitheredLODFadingOutMaskPass,
197 const bool bShadowProjection = false,
198 const bool bSecondStageDepthPass = false);
199
200 virtual void AddMeshBatch(const FMeshBatch& RESTRICT MeshBatch, uint64 BatchElementMask, const FPrimitiveSceneProxy* RESTRICT PrimitiveSceneProxy, int32 StaticMeshId = -1) override final;
201 virtual void CollectPSOInitializers(const FSceneTexturesConfig& SceneTexturesConfig, const FMaterial& Material, const FPSOPrecacheVertexFactoryData& VertexFactoryData, const FPSOPrecacheParams& PreCacheParams, TArray<FPSOPrecacheData>& PSOInitializers) override final;
202
203private:
204
205 bool TryAddMeshBatch(const FMeshBatch& RESTRICT MeshBatch, uint64 BatchElementMask, const FPrimitiveSceneProxy* RESTRICT PrimitiveSceneProxy, int32 StaticMeshId, const FMaterialRenderProxy& MaterialRenderProxy, const FMaterial& Material);
206
207 template<bool bPositionOnly>
208 bool Process(
209 const FMeshBatch& MeshBatch,
212 const FPrimitiveSceneProxy* RESTRICT PrimitiveSceneProxy,
213 const FMaterialRenderProxy& RESTRICT MaterialRenderProxy,
214 const FMaterial& RESTRICT MaterialResource,
215 ERasterizerFillMode MeshFillMode,
216 ERasterizerCullMode MeshCullMode);
217
219
220 void CollectDefaultMaterialPSOInitializers(
221 const FSceneTexturesConfig& SceneTexturesConfig,
222 const FMaterial& Material,
223 const FPSOPrecacheVertexFactoryData& VertexFactoryData,
225
226 template<bool bPositionOnly>
227 void CollectPSOInitializersInternal(
228 const FSceneTexturesConfig& SceneTexturesConfig,
229 const FPSOPrecacheVertexFactoryData& VertexFactoryData,
230 const FMaterial& RESTRICT MaterialResource,
231 ERasterizerFillMode MeshFillMode,
232 ERasterizerCullMode MeshCullMode,
233 bool bDitheredLODTransition,
234 EPrimitiveType PrimitiveType,
236
237 FMeshPassProcessorRenderState PassDrawRenderState;
238
239 const bool bRespectUseAsOccluderFlag;
240 const EDepthDrawingMode EarlyZPassMode;
241 const bool bEarlyZPassMovable;
242 const bool bDitheredLODFadingOutMaskPass;
243 const bool bShadowProjection;
244 const bool bSecondStageDepthPass;
245};
246
247extern void SetupDepthPassState(FMeshPassProcessorRenderState& DrawRenderState);
248
250{
251public:
252
258 const bool InbEarlyZPassMovable,
260
262
263private:
264
266 void Process(
267 const FMeshBatch& MeshBatch,
270 EBlendMode BlendMode,
271 const FPrimitiveSceneProxy* RESTRICT PrimitiveSceneProxy,
272 const FMaterialRenderProxy& RESTRICT MaterialRenderProxy,
273 const FMaterial& RESTRICT MaterialResource,
274 ERasterizerFillMode MeshFillMode,
275 ERasterizerCullMode MeshCullMode);
276
277 FMeshPassProcessorRenderState PassDrawRenderState;
278
279 const bool bRespectUseAsOccluderFlag;
280 const EDepthDrawingMode EarlyZPassMode;
281 const bool bEarlyZPassMovable;
282};
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define RESTRICT
Definition Platform.h:706
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool GetDepthPassShaders(const FMaterial &Material, const FVertexFactoryType *VertexFactoryType, ERHIFeatureLevel::Type FeatureLevel, bool bMaterialUsesPixelDepthOffset, TShaderRef< TDepthOnlyVS< bPositionOnly > > &VertexShader, TShaderRef< FDepthOnlyPS > &PixelShader, FShaderPipelineRef &ShaderPipeline)
Definition DepthRendering.cpp:163
EDepthDrawingMode
Definition DepthRendering.h:21
@ DDM_MaskedOnly
Definition DepthRendering.h:31
@ DDM_AllOpaque
Definition DepthRendering.h:29
@ DDM_None
Definition DepthRendering.h:23
@ DDM_NonMaskedOnly
Definition DepthRendering.h:25
@ DDM_AllOpaqueNoVelocity
Definition DepthRendering.h:33
@ DDM_AllOccluders
Definition DepthRendering.h:27
void AddDitheredStencilFillPass(FRDGBuilder &GraphBuilder, TConstArrayView< FViewInfo > Views, FRDGTextureRef DepthTexture, const FDepthPassInfo &DepthPass)
Definition DepthRendering.cpp:299
FDepthPassInfo GetDepthPassInfo(const FScene *Scene)
Definition DepthRendering.cpp:92
void AddDitheredStencilClearPass(FRDGBuilder &GraphBuilder, FRDGTextureRef DepthTexture, EShaderPlatform ShaderPlatform, bool bClearAllStencilBits)
Definition DepthRendering.cpp:387
FMeshDrawCommandSortKey CalculateDepthPassMeshStaticSortKey(const bool bIsMasked, const FMeshMaterialShader *VertexShader, const FMeshMaterialShader *PixelShader)
Definition DepthRendering.cpp:758
const TCHAR * GetDepthDrawingModeString(EDepthDrawingMode Mode)
Definition DepthRendering.cpp:130
void SetupDepthPassState(FMeshPassProcessorRenderState &DrawRenderState)
Definition DepthRendering.cpp:516
EBlendMode
Definition EngineTypes.h:245
ENGINE_API bool IsTranslucentBlendMode(EBlendMode BlendMode)
ERasterizerCullMode
Definition RHIDefinitions.h:369
ERasterizerFillMode
Definition RHIDefinitions.h:358
EPrimitiveType
Definition RHIDefinitions.h:822
EShaderPlatform
Definition RHIShaderPlatform.h:11
ERDGPassFlags
Definition RenderGraphDefinitions.h:128
bool AllowDebugViewmodes()
Definition ShaderCore.cpp:578
#define DECLARE_SHADER_TYPE(ShaderClass, ShaderMetaTypeShortcut,...)
Definition Shader.h:1688
Definition DepthRendering.h:123
static void ModifyCompilationEnvironment(const FMaterialShaderPermutationParameters &Parameters, FShaderCompilerEnvironment &OutEnvironment)
Definition DepthRendering.h:144
FDepthOnlyPS()
Definition DepthRendering.h:156
FDepthOnlyPS(const ShaderMetaType::CompiledShaderInitializerType &Initializer)
Definition DepthRendering.h:139
void GetShaderBindings(const FScene *Scene, ERHIFeatureLevel::Type FeatureLevel, const FPrimitiveSceneProxy *PrimitiveSceneProxy, const FMaterialRenderProxy &MaterialRenderProxy, const FMaterial &Material, const FMeshMaterialShaderElementData &ShaderElementData, FMeshDrawSingleShaderBindings &ShaderBindings) const
Definition DepthRendering.h:158
static bool ShouldCompilePermutation(const FMeshMaterialShaderPermutationParameters &Parameters)
Definition DepthRendering.h:126
Definition DepthRendering.h:182
virtual void CollectPSOInitializers(const FSceneTexturesConfig &SceneTexturesConfig, const FMaterial &Material, const FPSOPrecacheVertexFactoryData &VertexFactoryData, const FPSOPrecacheParams &PreCacheParams, TArray< FPSOPrecacheData > &PSOInitializers) override final
Definition DepthRendering.cpp:1111
virtual void AddMeshBatch(const FMeshBatch &RESTRICT MeshBatch, uint64 BatchElementMask, const FPrimitiveSceneProxy *RESTRICT PrimitiveSceneProxy, int32 StaticMeshId=-1) override final
Definition DepthRendering.cpp:1036
Definition MaterialRenderProxy.h:102
Definition MaterialShared.h:2058
Definition MeshPassProcessor.h:1482
Definition MeshDrawShaderBindings.h:104
Definition MeshMaterialShader.h:22
Definition MeshMaterialShader.h:68
RENDERER_API void GetShaderBindings(const FScene *Scene, ERHIFeatureLevel::Type FeatureLevel, const FPrimitiveSceneProxy *PrimitiveSceneProxy, const FMaterialRenderProxy &MaterialRenderProxy, const FMaterial &Material, const FMeshMaterialShaderElementData &ShaderElementData, FMeshDrawSingleShaderBindings &ShaderBindings) const
Definition ShaderBaseClasses.cpp:457
Definition MeshPassProcessor.h:1670
Definition MeshPassProcessor.h:2199
const FScene *RESTRICT Scene
Definition MeshPassProcessor.h:2203
ERHIFeatureLevel::Type FeatureLevel
Definition MeshPassProcessor.h:2204
Definition PrimitiveSceneProxy.h:296
Definition RenderGraphBuilder.h:49
Definition RenderGraphResources.h:571
Definition DepthRendering.h:250
virtual void AddMeshBatch(const FMeshBatch &RESTRICT MeshBatch, uint64 BatchElementMask, const FPrimitiveSceneProxy *RESTRICT PrimitiveSceneProxy, int32 StaticMeshId=-1) override final
FRayTracingDitheredLODMeshProcessor(const FScene *Scene, const FSceneView *InViewIfDynamicMeshCommand, const FMeshPassProcessorRenderState &InPassDrawRenderState, const bool InbRespectUseAsOccluderFlag, const EDepthDrawingMode InEarlyZPassMode, const bool InbEarlyZPassMovable, FMeshPassDrawListContext *InDrawListContext)
Definition SceneView.h:1425
Definition ScenePrivate.h:2875
Definition Shader.h:2273
static void ModifyCompilationEnvironment(const FShaderPermutationParameters &, FShaderCompilerEnvironment &)
Definition Shader.h:854
Definition StaticMeshBatch.h:16
Definition VertexFactory.h:314
bool SupportsPositionOnly() const
Definition VertexFactory.h:409
bool SupportsNaniteRendering() const
Definition VertexFactory.h:412
Definition SceneRendering.h:1132
Definition Array.h:670
Definition ConcurrentLinearAllocator.h:571
Definition DepthRendering.h:68
void GetShaderBindings(const FScene *Scene, ERHIFeatureLevel::Type FeatureLevel, const FPrimitiveSceneProxy *PrimitiveSceneProxy, const FMaterialRenderProxy &MaterialRenderProxy, const FMaterial &Material, const FMeshMaterialShaderElementData &ShaderElementData, FMeshDrawSingleShaderBindings &ShaderBindings) const
Definition DepthRendering.h:106
TDepthOnlyVS()
Definition DepthRendering.h:72
static void ModifyCompilationEnvironment(const FMaterialShaderPermutationParameters &Parameters, FShaderCompilerEnvironment &OutEnvironment)
Definition DepthRendering.h:101
TDepthOnlyVS(const FMeshMaterialShaderType::CompiledShaderInitializerType &Initializer)
Definition DepthRendering.h:74
static bool ShouldCompilePermutation(const FMeshMaterialShaderPermutationParameters &Parameters)
Definition DepthRendering.h:80
Definition Shader.h:1021
Type
Definition MeshPassProcessor.h:38
Type
Definition RHIFeatureLevel.h:20
Definition DepthRendering.h:39
bool IsRasterStencilDitherEnabled() const
Definition DepthRendering.h:45
bool IsComputeStencilDitherEnabled() const
Definition DepthRendering.h:40
EDepthDrawingMode EarlyZPassMode
Definition DepthRendering.h:50
bool bEarlyZPassMovable
Definition DepthRendering.h:51
bool bDitheredLODTransitionsUseStencil
Definition DepthRendering.h:52
ERDGPassFlags StencilDitherPassFlags
Definition DepthRendering.h:53
uint64 bHasPixelDepthOffsetConnected
Definition MaterialShared.h:1117
uint64 bWritesEveryPixel
Definition MaterialShared.h:1102
uint64 bIsSpecialEngineMaterial
Definition MaterialShared.h:1095
FMaterialShadingModelField ShadingModels
Definition MaterialShared.h:1065
uint64 bMaterialMayModifyMeshPosition
Definition MaterialShared.h:1118
uint64 bIsTranslucencyWritingCustomDepth
Definition MaterialShared.h:1136
Definition MaterialShader.h:45
FMaterialShaderParameters MaterialParameters
Definition MaterialShader.h:46
bool HasShadingModel(EMaterialShadingModel InShadingModel) const
Definition EngineTypes.h:756
Definition MeshBatch.h:371
Definition MeshMaterialShader.h:33
const FVertexFactoryType * VertexFactoryType
Definition MeshMaterialShader.h:35
Definition MeshMaterialShaderType.h:29
Definition MeshPassProcessor.h:2118
Definition PSOPrecache.h:30
Definition PSOPrecache.h:150
Definition SceneTexturesConfig.h:114
Definition ShaderCore.h:544
const EShaderPlatform Platform
Definition ShaderPermutation.h:29