--- title: 未命名 date: 2024-05-10 16:30:16 excerpt: tags: rating: ⭐ --- PostProcesss ```c++ void AddPostProcessingPasses( FRDGBuilder& GraphBuilder, const FViewInfo& View, int32 ViewIndex, FSceneUniformBuffer& SceneUniformBuffer, bool bAnyLumenActive, bool bLumenGIEnabled, EReflectionsMethod ReflectionsMethod, const FPostProcessingInputs& Inputs, const Nanite::FRasterResults* NaniteRasterResults, FInstanceCullingManager& InstanceCullingManager, FVirtualShadowMapArray* VirtualShadowMapArray, FLumenSceneFrameTemporaries& LumenFrameTemporaries, const FSceneWithoutWaterTextures& SceneWithoutWaterTextures, FScreenPassTexture TSRMoireInput) { RDG_CSV_STAT_EXCLUSIVE_SCOPE(GraphBuilder, RenderPostProcessing); QUICK_SCOPE_CYCLE_COUNTER(STAT_PostProcessing_Process); check(IsInRenderingThread()); check(View.VerifyMembersChecks()); Inputs.Validate(); FScene* Scene = View.Family->Scene->GetRenderScene(); const FIntRect PrimaryViewRect = View.ViewRect; const FSceneTextureParameters SceneTextureParameters = GetSceneTextureParameters(GraphBuilder, Inputs.SceneTextures); const FScreenPassRenderTarget ViewFamilyOutput = FScreenPassRenderTarget::CreateViewFamilyOutput(Inputs.ViewFamilyTexture, View); const FScreenPassTexture SceneDepth(SceneTextureParameters.SceneDepthTexture, PrimaryViewRect); const FScreenPassTexture CustomDepth(Inputs.CustomDepthTexture, PrimaryViewRect); const FScreenPassTexture Velocity(SceneTextureParameters.GBufferVelocityTexture, PrimaryViewRect); const FScreenPassTexture BlackDummy(GSystemTextures.GetBlackDummy(GraphBuilder)); const FTranslucencyPassResources& PostDOFTranslucencyResources = Inputs.TranslucencyViewResourcesMap.Get(ETranslucencyPass::TPT_TranslucencyAfterDOF); 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(); } ``` 考虑使用形参 - const FSceneTextures* SceneTextures - const FSceneTextures& SceneTextures - FSceneTextures& SceneTextures # OutlinePass ``` ```