diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md index a21fcd4..27b4c17 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/ToonPostLightingPass/OutlinePass.md @@ -5,7 +5,7 @@ excerpt: tags: rating: ⭐ --- - +PostProcesss ```c++ void AddPostProcessingPasses( FRDGBuilder& GraphBuilder, @@ -45,13 +45,67 @@ FLumenSceneFrameTemporaries& LumenFrameTemporaries, const FTranslucencyPassResources& PostMotionBlurTranslucencyResources = Inputs.TranslucencyViewResourcesMap.Get(ETranslucencyPass::TPT_TranslucencyAfterMotionBlur); ``` +# BasePass +```c++ +#if WITH_EDITOR + if (ViewFamily.EngineShowFlags.Wireframe) + { + checkf(ExclusiveDepthStencil.IsDepthWrite(), TEXT("Wireframe base pass requires depth-write, but it is set to read-only.")); + BasePassTextureCount = 1; + BasePassTextures[0] = SceneTextures.EditorPrimitiveColor; + BasePassTexturesView = MakeArrayView(BasePassTextures.GetData(), BasePassTextureCount); + + BasePassDepthTexture = SceneTextures.EditorPrimitiveDepth; + + auto* PassParameters = GraphBuilder.AllocParameters(); + PassParameters->RenderTargets = GetRenderTargetBindings(ERenderTargetLoadAction::EClear, BasePassTexturesView); + PassParameters->RenderTargets.DepthStencil = FDepthStencilBinding(BasePassDepthTexture, ERenderTargetLoadAction::EClear, ERenderTargetLoadAction::EClear, ExclusiveDepthStencil); + + GraphBuilder.AddPass(RDG_EVENT_NAME("WireframeClear"), PassParameters, ERDGPassFlags::Raster, [](FRHICommandList&) {}); + } +#endif + + // Render targets bindings should remain constant at this point. + FRenderTargetBindingSlots BasePassRenderTargets = GetRenderTargetBindings(ERenderTargetLoadAction::ELoad, BasePassTexturesView); + BasePassRenderTargets.DepthStencil = FDepthStencilBinding(BasePassDepthTexture, ERenderTargetLoadAction::ELoad, ERenderTargetLoadAction::ELoad, ExclusiveDepthStencil); + + FForwardBasePassTextures ForwardBasePassTextures{}; + + if (bForwardShadingEnabled) + { + ForwardBasePassTextures.SceneDepthIfResolved = SceneTextures.Depth.IsSeparate() ? SceneTextures.Depth.Resolve : nullptr; + ForwardBasePassTextures.ScreenSpaceAO = SceneTextures.ScreenSpaceAO; + ForwardBasePassTextures.ScreenSpaceShadowMask = ForwardShadowMaskTexture; + } + else if (!ExclusiveDepthStencil.IsDepthWrite()) + { + // If depth write is not enabled, we can bound the depth texture as read only + ForwardBasePassTextures.SceneDepthIfResolved = SceneTextures.Depth.Resolve; + } + ForwardBasePassTextures.bIs24BitUnormDepthStencil = ForwardBasePassTextures.SceneDepthIfResolved ? GPixelFormats[ForwardBasePassTextures.SceneDepthIfResolved->Desc.Format].bIs24BitUnormDepthStencil : 1; + + GraphBuilder.SetCommandListStat(GET_STATID(STAT_CLM_BasePass)); + RenderBasePassInternal(GraphBuilder, SceneTextures, BasePassRenderTargets, BasePassDepthStencilAccess, ForwardBasePassTextures, DBufferTextures, bDoParallelBasePass, bRenderLightmapDensity, InstanceCullingManager, bNaniteEnabled, NaniteRasterResults); + GraphBuilder.SetCommandListStat(GET_STATID(STAT_CLM_AfterBasePass)); + + + + FRenderTargetBindingSlots BasePassRenderTargets = GetRenderTargetBindings(ERenderTargetLoadAction::ELoad, BasePassTexturesView); + BasePassRenderTargets.DepthStencil = FDepthStencilBinding(BasePassDepthTexture, ERenderTargetLoadAction::ELoad, ERenderTargetLoadAction::ELoad, ExclusiveDepthStencil); + + RenderBasePassInternal(GraphBuilder, SceneTextures, BasePassRenderTargets, BasePassDepthStencilAccess, ForwardBasePassTextures, DBufferTextures, bDoParallelBasePass, bRenderLightmapDensity, InstanceCullingManager, bNaniteEnabled, NaniteRasterResults); +``` ## 读取GBufferTexture 位于SceneRendering.h +```c++ FORCEINLINE FSceneTextures& GetActiveSceneTextures() { return ViewFamily.GetSceneTextures(); } +``` -FSceneTextures& SceneTextures = GetActiveSceneTextures(); - +考虑使用形参 +- const FSceneTextures* SceneTextures +- const FSceneTextures& SceneTextures +- FSceneTextures& SceneTextures # OutlinePass ```