diff --git a/03-UnrealEngine/Rendering/RenderingPipeline/Materials/MeshDraw.md b/03-UnrealEngine/Rendering/RenderingPipeline/Materials/MeshDraw.md index ee6d8f7..683da3a 100644 --- a/03-UnrealEngine/Rendering/RenderingPipeline/Materials/MeshDraw.md +++ b/03-UnrealEngine/Rendering/RenderingPipeline/Materials/MeshDraw.md @@ -32,6 +32,73 @@ PS.使用的Shader必须是`FNaniteGlobalShader`的子类。 DrawNaniteMaterialPass() => SubmitNaniteIndirectMaterial() ## DepthStencil +***TStaticDepthStencilState*** +- RDG 04 Graphics Pipeline State Initializer https://zhuanlan.zhihu.com/p/582020846 + + +```c++ +DrawRenderState.SetDepthStencilState(TStaticDepthStencilState::GetRHI()); + +template +void SetDepthStencilStateForBasePass_Internal(FMeshPassProcessorRenderState& InDrawRenderState) +{ + InDrawRenderState.SetDepthStencilState(TStaticDepthStencilState< + bDepthTest, CompareFunction, + true, CF_Always, SO_Keep, SO_Keep, SO_Replace, + false, CF_Always, SO_Keep, SO_Keep, SO_Keep, + 0xFF, StencilWriteMask>::GetRHI()); +} + +template +void SetDepthStencilStateForBasePass_Internal(FMeshPassProcessorRenderState& InDrawRenderState, ERHIFeatureLevel::Type FeatureLevel) +{ + const static bool bStrataDufferPassEnabled = Strata::IsStrataEnabled() && Strata::IsDBufferPassEnabled(GShaderPlatformForFeatureLevel[FeatureLevel]); + if (bStrataDufferPassEnabled) + { + SetDepthStencilStateForBasePass_Internal(InDrawRenderState); + } + else + { + SetDepthStencilStateForBasePass_Internal(InDrawRenderState); + } +} + +void SetDepthStencilStateForBasePass( + FMeshPassProcessorRenderState& DrawRenderState, + ERHIFeatureLevel::Type FeatureLevel, + bool bDitheredLODTransition, + const FMaterial& MaterialResource, + bool bEnableReceiveDecalOutput, + bool bForceEnableStencilDitherState) +{ + const bool bMaskedInEarlyPass = (MaterialResource.IsMasked() || bDitheredLODTransition) && MaskedInEarlyPass(GShaderPlatformForFeatureLevel[FeatureLevel]); + if (bEnableReceiveDecalOutput) + { + if (bMaskedInEarlyPass) + { + SetDepthStencilStateForBasePass_Internal(DrawRenderState, FeatureLevel); + } + else if (DrawRenderState.GetDepthStencilAccess() & FExclusiveDepthStencil::DepthWrite) + { + SetDepthStencilStateForBasePass_Internal(DrawRenderState, FeatureLevel); + } + else + { + SetDepthStencilStateForBasePass_Internal(DrawRenderState, FeatureLevel); + } + } + else if (bMaskedInEarlyPass) + { + DrawRenderState.SetDepthStencilState(TStaticDepthStencilState::GetRHI()); + } + + if (bForceEnableStencilDitherState) + { + SetDepthStencilStateForBasePass_Internal(DrawRenderState, FeatureLevel); + } +} +``` + ### InitCustomDepthStencilContext() 根据当前平台是否支持使用ComputeShader直接输出结果(bComputeExport)、以及是否写入Stencil缓存,以此来创建不同的资源。最终输出FCustomDepthContext。 ```c++