diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/BasePass C++.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/BasePass C++.md index 344d3f7..cf20a20 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/BasePass C++.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ShaderModel/BasePass C++.md @@ -5,6 +5,62 @@ excerpt: tags: rating: ⭐ --- +# RenderBasePass() +传入RenderBasePass()的DepthStencil逻辑如下: +```c++ +const FExclusiveDepthStencil::Type BasePassDepthStencilAccess = + bAllowReadOnlyDepthBasePass + ? FExclusiveDepthStencil::DepthRead_StencilWrite + : FExclusiveDepthStencil::DepthWrite_StencilWrite; +``` + + +FDeferredShadingSceneRenderer::RenderBasePass() => +FDeferredShadingSceneRenderer::RenderBasePassInternal() => + + +FBasePassMeshProcessor::TryAddMeshBatch => + +## 大致流程 +1. 绑定GBuffer与Depth。 +```c++ +const FExclusiveDepthStencil ExclusiveDepthStencil(BasePassDepthStencilAccess); + +TStaticArray BasePassTextures; +uint32 BasePassTextureCount = SceneTextures.GetGBufferRenderTargets(BasePassTextures); +Strata::AppendStrataMRTs(*this, BasePassTextureCount, BasePassTextures); +TArrayView BasePassTexturesView = MakeArrayView(BasePassTextures.GetData(), BasePassTextureCount); +FRDGTextureRef BasePassDepthTexture = SceneTextures.Depth.Target; +``` +2. GBuffer Clear +```c++ +GraphBuilder.AddPass(RDG_EVENT_NAME("GBufferClear"), PassParameters, ERDGPassFlags::Raster, + [PassParameters, ColorLoadAction, SceneColorClearValue](FRHICommandList& RHICmdList) + { + // If no fast-clear action was used, we need to do an MRT shader clear. + if (ColorLoadAction == ERenderTargetLoadAction::ENoAction) + { + const FRenderTargetBindingSlots& RenderTargets = PassParameters->RenderTargets; + FLinearColor ClearColors[MaxSimultaneousRenderTargets]; + FRHITexture* Textures[MaxSimultaneousRenderTargets]; + int32 TextureIndex = 0; + + RenderTargets.Enumerate([&](const FRenderTargetBinding& RenderTarget) + { + FRHITexture* TextureRHI = RenderTarget.GetTexture()->GetRHI(); + ClearColors[TextureIndex] = TextureIndex == 0 ? SceneColorClearValue : TextureRHI->GetClearColor(); + Textures[TextureIndex] = TextureRHI; + ++TextureIndex; + }); + + // Clear color only; depth-stencil is fast cleared. + DrawClearQuadMRT(RHICmdList, true, TextureIndex, ClearColors, false, 0, false, 0); + } + }); +``` +3. + + # SetDepthStencilStateForBasePass() ```c++ void SetDepthStencilStateForBasePass(