当前位置:   article > 正文

UE4 后处理流程_ue downsample

ue downsample

GEngine\Source\Runtime\Renderer\Private\DeferredShadingRenderer.cpp

FDeferredShadingSceneRenderer::Render()

  1. // Finish rendering for each view.
  2. if (ViewFamily.bResolveScene && ViewFamilyTexture)
  3. {
  4. RDG_EVENT_SCOPE(GraphBuilder, "PostProcessing");
  5. RDG_GPU_STAT_SCOPE(GraphBuilder, Postprocessing);
  6. SCOPE_CYCLE_COUNTER(STAT_FinishRenderViewTargetTime);
  7. AddSetCurrentStatPass(GraphBuilder, GET_STATID(STAT_CLM_PostProcessing));
  8. FPostProcessingInputs PostProcessingInputs;
  9. PostProcessingInputs.ViewFamilyTexture = ViewFamilyTexture;
  10. PostProcessingInputs.SeparateTranslucencyTextures = &SeparateTranslucencyTextures;
  11. PostProcessingInputs.SceneTextures = SceneTextures;
  12. if (ViewFamily.UseDebugViewPS())
  13. {
  14. for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
  15. {
  16. const FViewInfo& View = Views[ViewIndex];
  17. RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
  18. RDG_EVENT_SCOPE_CONDITIONAL(GraphBuilder, Views.Num() > 1, "View%d", ViewIndex);
  19. AddDebugViewPostProcessingPasses(GraphBuilder, View, PostProcessingInputs);
  20. }
  21. }
  22. else
  23. {
  24. for (int32 ViewExt = 0; ViewExt < ViewFamily.ViewExtensions.Num(); ++ViewExt)
  25. {
  26. for (int32 ViewIndex = 0; ViewIndex < ViewFamily.Views.Num(); ++ViewIndex)
  27. {
  28. FViewInfo& View = Views[ViewIndex];
  29. RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
  30. ViewFamily.ViewExtensions[ViewExt]->PrePostProcessPass_RenderThread(GraphBuilder, View, PostProcessingInputs);
  31. }
  32. }
  33. for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
  34. {
  35. const FViewInfo& View = Views[ViewIndex];
  36. RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
  37. RDG_EVENT_SCOPE_CONDITIONAL(GraphBuilder, Views.Num() > 1, "View%d", ViewIndex);
  38. #if !(UE_BUILD_SHIPPING)
  39. if (IsPostProcessVisualizeCalibrationMaterialEnabled(View))
  40. {
  41. const UMaterialInterface* DebugMaterialInterface = GetPostProcessVisualizeCalibrationMaterialInterface(View);
  42. check(DebugMaterialInterface);
  43. AddVisualizeCalibrationMaterialPostProcessingPasses(GraphBuilder, View, PostProcessingInputs, DebugMaterialInterface);
  44. }
  45. else
  46. #endif
  47. {
  48. AddPostProcessingPasses(GraphBuilder, View, PostProcessingInputs);
  49. }
  50. }
  51. }
  52. AddPass(GraphBuilder, [this, &SceneContext](FRHICommandListImmediate&)
  53. {
  54. SceneContext.SetSceneColor(nullptr);
  55. });
  56. }

\Engine\Source\Runtime\Renderer\Private\PostProcess\PostProcessing.cpp

  1. void AddPostProcessingPasses(FRDGBuilder& GraphBuilder, const FViewInfo& View, const FPostProcessingInputs& Inputs)
  2. {
  3. RDG_CSV_STAT_EXCLUSIVE_SCOPE(GraphBuilder, RenderPostProcessing);
  4. QUICK_SCOPE_CYCLE_COUNTER(STAT_PostProcessing_Process);
  5. check(IsInRenderingThread());
  6. check(View.VerifyMembersChecks());
  7. Inputs.Validate();
  8. const FIntRect PrimaryViewRect = View.ViewRect;
  9. const FSceneTextureParameters SceneTextureParameters = GetSceneTextureParameters(GraphBuilder, Inputs.SceneTextures);
  10. const FScreenPassRenderTarget ViewFamilyOutput = FScreenPassRenderTarget::CreateViewFamilyOutput(Inputs.ViewFamilyTexture, View);
  11. const FScreenPassTexture SceneDepth(SceneTextureParameters.SceneDepthTexture, PrimaryViewRect);
  12. const FScreenPassTexture SeparateTranslucency(Inputs.SeparateTranslucencyTextures->GetColorForRead(GraphBuilder), PrimaryViewRect);
  13. const FScreenPassTexture CustomDepth((*Inputs.SceneTextures)->CustomDepthTexture, PrimaryViewRect);
  14. const FScreenPassTexture Velocity(SceneTextureParameters.GBufferVelocityTexture, PrimaryViewRect);
  15. const FScreenPassTexture BlackDummy(GSystemTextures.GetBlackDummy(GraphBuilder));
  16. // Scene color is updated incrementally through the post process pipeline.
  17. FScreenPassTexture SceneColor((*Inputs.SceneTextures)->SceneColorTexture, PrimaryViewRect);
  18. // Assigned before and after the tonemapper.
  19. FScreenPassTexture SceneColorBeforeTonemap;
  20. FScreenPassTexture SceneColorAfterTonemap;
  21. // Unprocessed scene color stores the original input.
  22. const FScreenPassTexture OriginalSceneColor = SceneColor;
  23. // Default the new eye adaptation to the last one in case it's not generated this frame.
  24. const FEyeAdaptationParameters EyeAdaptationParameters = GetEyeAdaptationParameters(View, ERHIFeatureLevel::SM5);
  25. FRDGTextureRef LastEyeAdaptationTexture = GetEyeAdaptationTexture(GraphBuilder, View);
  26. FRDGTextureRef EyeAdaptationTexture = LastEyeAdaptationTexture;
  27. // Histogram defaults to black because the histogram eye adaptation pass is used for the manual metering mode.
  28. FRDGTextureRef HistogramTexture = BlackDummy.Texture;
  29. const FEngineShowFlags& EngineShowFlags = View.Family->EngineShowFlags;
  30. const bool bVisualizeHDR = EngineShowFlags.VisualizeHDR;
  31. const bool bViewFamilyOutputInHDR = GRHISupportsHDROutput && IsHDREnabled();
  32. const bool bVisualizeGBufferOverview = IsVisualizeGBufferOverviewEnabled(View);
  33. const bool bVisualizeGBufferDumpToFile = IsVisualizeGBufferDumpToFileEnabled(View);
  34. const bool bVisualizeGBufferDumpToPIpe = IsVisualizeGBufferDumpToPipeEnabled(View);
  35. const bool bOutputInHDR = IsPostProcessingOutputInHDR();
  36. const FPaniniProjectionConfig PaniniConfig(View);
  37. enum class EPass : uint32
  38. {
  39. MotionBlur,
  40. Tonemap,
  41. FXAA,
  42. PostProcessMaterialAfterTonemapping,
  43. VisualizeDepthOfField,
  44. VisualizeStationaryLightOverlap,
  45. VisualizeLightCulling,
  46. SelectionOutline,
  47. EditorPrimitive,
  48. VisualizeShadingModels,
  49. VisualizeGBufferHints,
  50. VisualizeSubsurface,
  51. VisualizeGBufferOverview,
  52. VisualizeHDR,
  53. PixelInspector,
  54. HMDDistortion,
  55. HighResolutionScreenshotMask,
  56. PrimaryUpscale,
  57. SecondaryUpscale,
  58. MAX
  59. };
  60. const auto TranslatePass = [](ISceneViewExtension::EPostProcessingPass Pass) -> EPass
  61. {
  62. switch (Pass)
  63. {
  64. case ISceneViewExtension::EPostProcessingPass::MotionBlur : return EPass::MotionBlur;
  65. case ISceneViewExtension::EPostProcessingPass::Tonemap : return EPass::Tonemap;
  66. case ISceneViewExtension::EPostProcessingPass::FXAA : return EPass::FXAA;
  67. case ISceneViewExtension::EPostProcessingPass::VisualizeDepthOfField : return EPass::VisualizeDepthOfField;
  68. default:
  69. check(false);
  70. return EPass::MAX;
  71. };
  72. };
  73. const TCHAR* PassNames[] =
  74. {
  75. TEXT("MotionBlur"),
  76. TEXT("Tonemap"),
  77. TEXT("FXAA"),
  78. TEXT("PostProcessMaterial (AfterTonemapping)"),
  79. TEXT("VisualizeDepthOfField"),
  80. TEXT("VisualizeStationaryLightOverlap"),
  81. TEXT("VisualizeLightCulling"),
  82. TEXT("SelectionOutline"),
  83. TEXT("EditorPrimitive"),
  84. TEXT("VisualizeShadingModels"),
  85. TEXT("VisualizeGBufferHints"),
  86. TEXT("VisualizeSubsurface"),
  87. TEXT("VisualizeGBufferOverview"),
  88. TEXT("VisualizeHDR"),
  89. TEXT("PixelInspector"),
  90. TEXT("HMDDistortion"),
  91. TEXT("HighResolutionScreenshotMask"),
  92. TEXT("PrimaryUpscale"),
  93. TEXT("SecondaryUpscale")
  94. };
  95. static_assert(static_cast<uint32>(EPass::MAX) == UE_ARRAY_COUNT(PassNames), "EPass does not match PassNames.");
  96. TOverridePassSequence<EPass> PassSequence(ViewFamilyOutput);
  97. PassSequence.SetNames(PassNames, UE_ARRAY_COUNT(PassNames));
  98. PassSequence.SetEnabled(EPass::VisualizeStationaryLightOverlap, EngineShowFlags.StationaryLightOverlap);
  99. PassSequence.SetEnabled(EPass::VisualizeLightCulling, EngineShowFlags.VisualizeLightCulling);
  100. #if WITH_EDITOR
  101. PassSequence.SetEnabled(EPass::SelectionOutline, GIsEditor && EngineShowFlags.Selection && EngineShowFlags.SelectionOutline && !EngineShowFlags.Wireframe && !bVisualizeHDR && !IStereoRendering::IsStereoEyeView(View));
  102. PassSequence.SetEnabled(EPass::EditorPrimitive, FSceneRenderer::ShouldCompositeEditorPrimitives(View));
  103. #else
  104. PassSequence.SetEnabled(EPass::SelectionOutline, false);
  105. PassSequence.SetEnabled(EPass::EditorPrimitive, false);
  106. #endif
  107. PassSequence.SetEnabled(EPass::VisualizeShadingModels, EngineShowFlags.VisualizeShadingModels);
  108. PassSequence.SetEnabled(EPass::VisualizeGBufferHints, EngineShowFlags.GBufferHints);
  109. PassSequence.SetEnabled(EPass::VisualizeSubsurface, EngineShowFlags.VisualizeSSS);
  110. PassSequence.SetEnabled(EPass::VisualizeGBufferOverview, bVisualizeGBufferOverview || bVisualizeGBufferDumpToFile || bVisualizeGBufferDumpToPIpe);
  111. PassSequence.SetEnabled(EPass::VisualizeHDR, EngineShowFlags.VisualizeHDR);
  112. #if WITH_EDITOR
  113. PassSequence.SetEnabled(EPass::PixelInspector, View.bUsePixelInspector);
  114. #else
  115. PassSequence.SetEnabled(EPass::PixelInspector, false);
  116. #endif
  117. PassSequence.SetEnabled(EPass::HMDDistortion, EngineShowFlags.StereoRendering && EngineShowFlags.HMDDistortion);
  118. PassSequence.SetEnabled(EPass::HighResolutionScreenshotMask, IsHighResolutionScreenshotMaskEnabled(View));
  119. PassSequence.SetEnabled(EPass::PrimaryUpscale, PaniniConfig.IsEnabled() || (View.PrimaryScreenPercentageMethod == EPrimaryScreenPercentageMethod::SpatialUpscale && PrimaryViewRect.Size() != View.GetSecondaryViewRectSize()));
  120. PassSequence.SetEnabled(EPass::SecondaryUpscale, View.RequiresSecondaryUpscale());
  121. const auto GetPostProcessMaterialInputs = [&](FScreenPassTexture InSceneColor)
  122. {
  123. FPostProcessMaterialInputs PostProcessMaterialInputs;
  124. PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::SceneColor, InSceneColor);
  125. PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::SeparateTranslucency, SeparateTranslucency);
  126. PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::Velocity, Velocity);
  127. PostProcessMaterialInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
  128. PostProcessMaterialInputs.CustomDepthTexture = CustomDepth.Texture;
  129. return PostProcessMaterialInputs;
  130. };
  131. const auto AddAfterPass = [&](EPass InPass, FScreenPassTexture InSceneColor) -> FScreenPassTexture
  132. {
  133. // In some cases (e.g. OCIO color conversion) we want View Extensions to be able to add extra custom post processing after the pass.
  134. FAfterPassCallbackDelegateArray& PassCallbacks = PassSequence.GetAfterPassCallbacks(InPass);
  135. if (PassCallbacks.Num())
  136. {
  137. FPostProcessMaterialInputs InOutPostProcessAfterPassInputs = GetPostProcessMaterialInputs(InSceneColor);
  138. for (int32 AfterPassCallbackIndex = 0; AfterPassCallbackIndex < PassCallbacks.Num(); AfterPassCallbackIndex++)
  139. {
  140. FAfterPassCallbackDelegate& AfterPassCallback = PassCallbacks[AfterPassCallbackIndex];
  141. PassSequence.AcceptOverrideIfLastPass(InPass, InOutPostProcessAfterPassInputs.OverrideOutput, AfterPassCallbackIndex);
  142. InSceneColor = AfterPassCallback.Execute(GraphBuilder, View, InOutPostProcessAfterPassInputs);
  143. }
  144. }
  145. return MoveTemp(InSceneColor);
  146. };
  147. if (IsPostProcessingEnabled(View))
  148. {
  149. const EStereoscopicPass StereoPass = View.StereoPass;
  150. const bool bPrimaryView = IStereoRendering::IsAPrimaryView(View);
  151. const bool bHasViewState = View.ViewState != nullptr;
  152. const bool bDepthOfFieldEnabled = DiaphragmDOF::IsEnabled(View);
  153. const bool bVisualizeDepthOfField = bDepthOfFieldEnabled && EngineShowFlags.VisualizeDOF;
  154. const bool bVisualizeMotionBlur = IsVisualizeMotionBlurEnabled(View);
  155. const EAutoExposureMethod AutoExposureMethod = GetAutoExposureMethod(View);
  156. const EAntiAliasingMethod AntiAliasingMethod = !bVisualizeDepthOfField ? View.AntiAliasingMethod : AAM_None;
  157. const EDownsampleQuality DownsampleQuality = GetDownsampleQuality();
  158. const EPixelFormat DownsampleOverrideFormat = PF_FloatRGB;
  159. // Motion blur gets replaced by the visualization pass.
  160. const bool bMotionBlurEnabled = !bVisualizeMotionBlur && IsMotionBlurEnabled(View);
  161. // Skip tonemapping for visualizers which overwrite the HDR scene color.
  162. const bool bTonemapEnabled = !bVisualizeMotionBlur;
  163. const bool bTonemapOutputInHDR = View.Family->SceneCaptureSource == SCS_FinalColorHDR || View.Family->SceneCaptureSource == SCS_FinalToneCurveHDR || bOutputInHDR || bViewFamilyOutputInHDR;
  164. // We don't test for the EyeAdaptation engine show flag here. If disabled, the auto exposure pass is still executes but performs a clamp.
  165. const bool bEyeAdaptationEnabled =
  166. // Skip for transient views.
  167. bHasViewState &&
  168. // Skip for secondary views in a stereo setup.
  169. bPrimaryView;
  170. const bool bHistogramEnabled =
  171. // Force the histogram on when we are visualizing HDR.
  172. bVisualizeHDR ||
  173. // Skip if not using histogram eye adaptation.
  174. (bEyeAdaptationEnabled && AutoExposureMethod == EAutoExposureMethod::AEM_Histogram &&
  175. // Skip if we don't have any exposure range to generate (eye adaptation will clamp).
  176. View.FinalPostProcessSettings.AutoExposureMinBrightness < View.FinalPostProcessSettings.AutoExposureMaxBrightness);
  177. const bool bBloomEnabled = View.FinalPostProcessSettings.BloomIntensity > 0.0f;
  178. const FPostProcessMaterialChain PostProcessMaterialAfterTonemappingChain = GetPostProcessMaterialChain(View, BL_AfterTonemapping);
  179. PassSequence.SetEnabled(EPass::MotionBlur, bVisualizeMotionBlur || bMotionBlurEnabled);
  180. PassSequence.SetEnabled(EPass::Tonemap, bTonemapEnabled);
  181. PassSequence.SetEnabled(EPass::FXAA, AntiAliasingMethod == AAM_FXAA);
  182. PassSequence.SetEnabled(EPass::PostProcessMaterialAfterTonemapping, PostProcessMaterialAfterTonemappingChain.Num() != 0);
  183. PassSequence.SetEnabled(EPass::VisualizeDepthOfField, bVisualizeDepthOfField);
  184. for (int32 ViewExt = 0; ViewExt < View.Family->ViewExtensions.Num(); ++ViewExt)
  185. {
  186. for (int32 SceneViewPassId = 0; SceneViewPassId != static_cast<int>(ISceneViewExtension::EPostProcessingPass::MAX); SceneViewPassId++)
  187. {
  188. ISceneViewExtension::EPostProcessingPass SceneViewPass = static_cast<ISceneViewExtension::EPostProcessingPass>(SceneViewPassId);
  189. EPass PostProcessingPass = TranslatePass(SceneViewPass);
  190. View.Family->ViewExtensions[ViewExt]->SubscribeToPostProcessingPass(
  191. SceneViewPass,
  192. PassSequence.GetAfterPassCallbacks(PostProcessingPass),
  193. PassSequence.IsEnabled(PostProcessingPass));
  194. }
  195. }
  196. PassSequence.Finalize();
  197. // Post Process Material Chain - Before Translucency
  198. {
  199. const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_BeforeTranslucency);
  200. if (MaterialChain.Num())
  201. {
  202. SceneColor = AddPostProcessMaterialChain(GraphBuilder, View, GetPostProcessMaterialInputs(SceneColor), MaterialChain);
  203. }
  204. }
  205. // Diaphragm Depth of Field
  206. {
  207. FRDGTextureRef LocalSceneColorTexture = SceneColor.Texture;
  208. if (bDepthOfFieldEnabled)
  209. {
  210. LocalSceneColorTexture = DiaphragmDOF::AddPasses(GraphBuilder, SceneTextureParameters, View, SceneColor.Texture, *Inputs.SeparateTranslucencyTextures);
  211. }
  212. // DOF passes were not added, therefore need to compose Separate translucency manually.
  213. if (LocalSceneColorTexture == SceneColor.Texture)
  214. {
  215. LocalSceneColorTexture = AddSeparateTranslucencyCompositionPass(GraphBuilder, View, SceneColor.Texture, *Inputs.SeparateTranslucencyTextures);
  216. }
  217. SceneColor.Texture = LocalSceneColorTexture;
  218. }
  219. // Post Process Material Chain - Before Tonemapping
  220. {
  221. const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_BeforeTonemapping);
  222. if (MaterialChain.Num())
  223. {
  224. SceneColor = AddPostProcessMaterialChain(GraphBuilder, View, GetPostProcessMaterialInputs(SceneColor), MaterialChain);
  225. }
  226. }
  227. FScreenPassTexture HalfResolutionSceneColor;
  228. // Scene color view rectangle after temporal AA upscale to secondary screen percentage.
  229. FIntRect SecondaryViewRect = PrimaryViewRect;
  230. // Temporal Anti-aliasing. Also may perform a temporal upsample from primary to secondary view rect.
  231. if (AntiAliasingMethod == AAM_TemporalAA)
  232. {
  233. // Whether we allow the temporal AA pass to downsample scene color. It may choose not to based on internal context,
  234. // in which case the output half resolution texture will remain null.
  235. const bool bAllowSceneDownsample =
  236. IsTemporalAASceneDownsampleAllowed(View) &&
  237. // We can only merge if the normal downsample pass would happen immediately after.
  238. !bMotionBlurEnabled && !bVisualizeMotionBlur &&
  239. // TemporalAA is only able to match the low quality mode (box filter).
  240. GetDownsampleQuality() == EDownsampleQuality::Low;
  241. int32 UpscaleMode = ITemporalUpscaler::GetTemporalUpscalerMode();
  242. const ITemporalUpscaler* DefaultTemporalUpscaler = ITemporalUpscaler::GetDefaultTemporalUpscaler();
  243. const ITemporalUpscaler* UpscalerToUse = ( UpscaleMode == 0 || !View.Family->GetTemporalUpscalerInterface())? DefaultTemporalUpscaler : View.Family->GetTemporalUpscalerInterface();
  244. const TCHAR* UpscalerName = UpscalerToUse->GetDebugName();
  245. // Standard event scope for temporal upscaler to have all profiling information not matter what, and with explicit detection of third party.
  246. RDG_EVENT_SCOPE_CONDITIONAL(
  247. GraphBuilder,
  248. UpscalerToUse != DefaultTemporalUpscaler,
  249. "ThirdParty %s %dx%d -> %dx%d",
  250. UpscalerToUse->GetDebugName(),
  251. View.ViewRect.Width(), View.ViewRect.Height(),
  252. View.GetSecondaryViewRectSize().X, View.GetSecondaryViewRectSize().Y);
  253. ITemporalUpscaler::FPassInputs UpscalerPassInputs;
  254. UpscalerPassInputs.bAllowDownsampleSceneColor = bAllowSceneDownsample;
  255. UpscalerPassInputs.DownsampleOverrideFormat = DownsampleOverrideFormat;
  256. UpscalerPassInputs.SceneColorTexture = SceneColor.Texture;
  257. UpscalerPassInputs.SceneDepthTexture = SceneDepth.Texture;
  258. UpscalerPassInputs.SceneVelocityTexture = Velocity.Texture;
  259. UpscalerPassInputs.EyeAdaptationTexture = GetEyeAdaptationTexture(GraphBuilder, View);
  260. UpscalerToUse->AddPasses(
  261. GraphBuilder,
  262. View,
  263. UpscalerPassInputs,
  264. &SceneColor.Texture,
  265. &SecondaryViewRect,
  266. &HalfResolutionSceneColor.Texture,
  267. &HalfResolutionSceneColor.ViewRect);
  268. }
  269. else if (ShouldRenderScreenSpaceReflections(View))
  270. {
  271. // If we need SSR, and TAA is enabled, then AddTemporalAAPass() has already handled the scene history.
  272. // If we need SSR, and TAA is not enable, then we just need to extract the history.
  273. if (!View.bStatePrevViewInfoIsReadOnly)
  274. {
  275. check(View.ViewState);
  276. FTemporalAAHistory& OutputHistory = View.ViewState->PrevFrameViewInfo.TemporalAAHistory;
  277. GraphBuilder.QueueTextureExtraction(SceneColor.Texture, &OutputHistory.RT[0]);
  278. // For SSR, we still fill up the rest of the OutputHistory data using shared math from FTAAPassParameters.
  279. FTAAPassParameters TAAInputs(View);
  280. TAAInputs.SceneColorInput = SceneColor.Texture;
  281. TAAInputs.SetupViewRect(View);
  282. OutputHistory.ViewportRect = TAAInputs.OutputViewRect;
  283. OutputHistory.ReferenceBufferSize = TAAInputs.GetOutputExtent() * TAAInputs.ResolutionDivisor;
  284. }
  285. }
  286. //! SceneColorTexture is now upsampled to the SecondaryViewRect. Use SecondaryViewRect for input / output.
  287. SceneColor.ViewRect = SecondaryViewRect;
  288. // Post Process Material Chain - SSR Input
  289. if (View.ViewState && !View.bStatePrevViewInfoIsReadOnly)
  290. {
  291. const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_SSRInput);
  292. if (MaterialChain.Num())
  293. {
  294. // Save off SSR post process output for the next frame.
  295. FScreenPassTexture PassOutput = AddPostProcessMaterialChain(GraphBuilder, View, GetPostProcessMaterialInputs(SceneColor), MaterialChain);
  296. GraphBuilder.QueueTextureExtraction(PassOutput.Texture, &View.ViewState->PrevFrameViewInfo.CustomSSRInput);
  297. }
  298. }
  299. if (PassSequence.IsEnabled(EPass::MotionBlur))
  300. {
  301. FMotionBlurInputs PassInputs;
  302. PassSequence.AcceptOverrideIfLastPass(EPass::MotionBlur, PassInputs.OverrideOutput);
  303. PassInputs.SceneColor = SceneColor;
  304. PassInputs.SceneDepth = SceneDepth;
  305. PassInputs.SceneVelocity = Velocity;
  306. PassInputs.Quality = GetMotionBlurQuality();
  307. PassInputs.Filter = GetMotionBlurFilter();
  308. // Motion blur visualization replaces motion blur when enabled.
  309. if (bVisualizeMotionBlur)
  310. {
  311. SceneColor = AddVisualizeMotionBlurPass(GraphBuilder, View, PassInputs);
  312. }
  313. else
  314. {
  315. SceneColor = AddMotionBlurPass(GraphBuilder, View, PassInputs);
  316. }
  317. }
  318. SceneColor = AddAfterPass(EPass::MotionBlur, SceneColor);
  319. // If TAA didn't do it, downsample the scene color texture by half.
  320. if (!HalfResolutionSceneColor.Texture)
  321. {
  322. FDownsamplePassInputs PassInputs;
  323. PassInputs.Name = TEXT("HalfResolutionSceneColor");
  324. PassInputs.SceneColor = SceneColor;
  325. PassInputs.Quality = DownsampleQuality;
  326. PassInputs.FormatOverride = DownsampleOverrideFormat;
  327. HalfResolutionSceneColor = AddDownsamplePass(GraphBuilder, View, PassInputs);
  328. }
  329. // Store half res scene color in the history
  330. extern int32 GSSRHalfResSceneColor;
  331. if (ShouldRenderScreenSpaceReflections(View) && !View.bStatePrevViewInfoIsReadOnly && GSSRHalfResSceneColor)
  332. {
  333. check(View.ViewState);
  334. GraphBuilder.QueueTextureExtraction(HalfResolutionSceneColor.Texture, &View.ViewState->PrevFrameViewInfo.HalfResTemporalAAHistory);
  335. }
  336. FSceneDownsampleChain SceneDownsampleChain;
  337. if (bHistogramEnabled)
  338. {
  339. HistogramTexture = AddHistogramPass(GraphBuilder, View, EyeAdaptationParameters, HalfResolutionSceneColor, LastEyeAdaptationTexture);
  340. }
  341. if (bEyeAdaptationEnabled)
  342. {
  343. const bool bBasicEyeAdaptationEnabled = bEyeAdaptationEnabled && (AutoExposureMethod == EAutoExposureMethod::AEM_Basic);
  344. if (bBasicEyeAdaptationEnabled)
  345. {
  346. const bool bLogLumaInAlpha = true;
  347. SceneDownsampleChain.Init(GraphBuilder, View, EyeAdaptationParameters, HalfResolutionSceneColor, DownsampleQuality, bLogLumaInAlpha);
  348. // Use the alpha channel in the last downsample (smallest) to compute eye adaptations values.
  349. EyeAdaptationTexture = AddBasicEyeAdaptationPass(GraphBuilder, View, EyeAdaptationParameters, SceneDownsampleChain.GetLastTexture(), LastEyeAdaptationTexture);
  350. }
  351. // Add histogram eye adaptation pass even if no histogram exists to support the manual clamping mode.
  352. else
  353. {
  354. EyeAdaptationTexture = AddHistogramEyeAdaptationPass(GraphBuilder, View, EyeAdaptationParameters, HistogramTexture);
  355. }
  356. }
  357. FScreenPassTexture Bloom;
  358. if (bBloomEnabled)
  359. {
  360. FSceneDownsampleChain BloomDownsampleChain;
  361. FBloomInputs PassInputs;
  362. PassInputs.SceneColor = SceneColor;
  363. const bool bBloomThresholdEnabled = View.FinalPostProcessSettings.BloomThreshold > -1.0f;
  364. // Reuse the main scene downsample chain if a threshold isn't required for bloom.
  365. if (SceneDownsampleChain.IsInitialized() && !bBloomThresholdEnabled)
  366. {
  367. PassInputs.SceneDownsampleChain = &SceneDownsampleChain;
  368. }
  369. else
  370. {
  371. FScreenPassTexture DownsampleInput = HalfResolutionSceneColor;
  372. if (bBloomThresholdEnabled)
  373. {
  374. const float BloomThreshold = View.FinalPostProcessSettings.BloomThreshold;
  375. FBloomSetupInputs SetupPassInputs;
  376. SetupPassInputs.SceneColor = DownsampleInput;
  377. SetupPassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
  378. SetupPassInputs.Threshold = BloomThreshold;
  379. DownsampleInput = AddBloomSetupPass(GraphBuilder, View, SetupPassInputs);
  380. }
  381. const bool bLogLumaInAlpha = false;
  382. BloomDownsampleChain.Init(GraphBuilder, View, EyeAdaptationParameters, DownsampleInput, DownsampleQuality, bLogLumaInAlpha);
  383. PassInputs.SceneDownsampleChain = &BloomDownsampleChain;
  384. }
  385. FBloomOutputs PassOutputs = AddBloomPass(GraphBuilder, View, PassInputs);
  386. SceneColor = PassOutputs.SceneColor;
  387. Bloom = PassOutputs.Bloom;
  388. FScreenPassTexture LensFlares = AddLensFlaresPass(GraphBuilder, View, Bloom, *PassInputs.SceneDownsampleChain);
  389. if (LensFlares.IsValid())
  390. {
  391. // Lens flares are composited with bloom.
  392. Bloom = LensFlares;
  393. }
  394. }
  395. // Tonemapper needs a valid bloom target, even if it's black.
  396. if (!Bloom.IsValid())
  397. {
  398. Bloom = BlackDummy;
  399. }
  400. SceneColorBeforeTonemap = SceneColor;
  401. if (PassSequence.IsEnabled(EPass::Tonemap))
  402. {
  403. const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_ReplacingTonemapper);
  404. if (MaterialChain.Num())
  405. {
  406. const UMaterialInterface* HighestPriorityMaterial = MaterialChain[0];
  407. FPostProcessMaterialInputs PassInputs;
  408. PassSequence.AcceptOverrideIfLastPass(EPass::Tonemap, PassInputs.OverrideOutput);
  409. PassInputs.SetInput(EPostProcessMaterialInput::SceneColor, SceneColor);
  410. PassInputs.SetInput(EPostProcessMaterialInput::SeparateTranslucency, SeparateTranslucency);
  411. PassInputs.SetInput(EPostProcessMaterialInput::CombinedBloom, Bloom);
  412. PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
  413. PassInputs.CustomDepthTexture = CustomDepth.Texture;
  414. SceneColor = AddPostProcessMaterialPass(GraphBuilder, View, PassInputs, HighestPriorityMaterial);
  415. }
  416. else
  417. {
  418. FRDGTextureRef ColorGradingTexture = nullptr;
  419. if (bPrimaryView)
  420. {
  421. ColorGradingTexture = AddCombineLUTPass(GraphBuilder, View);
  422. }
  423. // We can re-use the color grading texture from the primary view.
  424. else if (View.GetTonemappingLUT())
  425. {
  426. ColorGradingTexture = TryRegisterExternalTexture(GraphBuilder, View.GetTonemappingLUT());
  427. }
  428. else
  429. {
  430. const FViewInfo* PrimaryView = static_cast<const FViewInfo*>(View.Family->Views[0]);
  431. ColorGradingTexture = TryRegisterExternalTexture(GraphBuilder, PrimaryView->GetTonemappingLUT());
  432. }
  433. FTonemapInputs PassInputs;
  434. PassSequence.AcceptOverrideIfLastPass(EPass::Tonemap, PassInputs.OverrideOutput);
  435. PassInputs.SceneColor = SceneColor;
  436. PassInputs.Bloom = Bloom;
  437. PassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
  438. PassInputs.ColorGradingTexture = ColorGradingTexture;
  439. PassInputs.bWriteAlphaChannel = AntiAliasingMethod == AAM_FXAA || IsPostProcessingWithAlphaChannelSupported();
  440. PassInputs.bOutputInHDR = bTonemapOutputInHDR;
  441. SceneColor = AddTonemapPass(GraphBuilder, View, PassInputs);
  442. }
  443. }
  444. SceneColor = AddAfterPass(EPass::Tonemap, SceneColor);
  445. SceneColorAfterTonemap = SceneColor;
  446. if (PassSequence.IsEnabled(EPass::FXAA))
  447. {
  448. FFXAAInputs PassInputs;
  449. PassSequence.AcceptOverrideIfLastPass(EPass::FXAA, PassInputs.OverrideOutput);
  450. PassInputs.SceneColor = SceneColor;
  451. PassInputs.Quality = GetFXAAQuality();
  452. SceneColor = AddFXAAPass(GraphBuilder, View, PassInputs);
  453. }
  454. SceneColor = AddAfterPass(EPass::FXAA, SceneColor);
  455. // Post Process Material Chain - After Tonemapping
  456. if (PassSequence.IsEnabled(EPass::PostProcessMaterialAfterTonemapping))
  457. {
  458. FPostProcessMaterialInputs PassInputs = GetPostProcessMaterialInputs(SceneColor);
  459. PassSequence.AcceptOverrideIfLastPass(EPass::PostProcessMaterialAfterTonemapping, PassInputs.OverrideOutput);
  460. PassInputs.SetInput(EPostProcessMaterialInput::PreTonemapHDRColor, SceneColorBeforeTonemap);
  461. PassInputs.SetInput(EPostProcessMaterialInput::PostTonemapHDRColor, SceneColorAfterTonemap);
  462. PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
  463. SceneColor = AddPostProcessMaterialChain(GraphBuilder, View, PassInputs, PostProcessMaterialAfterTonemappingChain);
  464. }
  465. if (PassSequence.IsEnabled(EPass::VisualizeDepthOfField))
  466. {
  467. FVisualizeDOFInputs PassInputs;
  468. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeDepthOfField, PassInputs.OverrideOutput);
  469. PassInputs.SceneColor = SceneColor;
  470. PassInputs.SceneDepth = SceneDepth;
  471. SceneColor = AddVisualizeDOFPass(GraphBuilder, View, PassInputs);
  472. }
  473. SceneColor = AddAfterPass(EPass::VisualizeDepthOfField, SceneColor);
  474. }
  475. // Minimal PostProcessing - Separate translucency composition and gamma-correction only.
  476. else
  477. {
  478. PassSequence.SetEnabled(EPass::MotionBlur, false);
  479. PassSequence.SetEnabled(EPass::Tonemap, true);
  480. PassSequence.SetEnabled(EPass::FXAA, false);
  481. PassSequence.SetEnabled(EPass::PostProcessMaterialAfterTonemapping, false);
  482. PassSequence.SetEnabled(EPass::VisualizeDepthOfField, false);
  483. PassSequence.Finalize();
  484. SceneColor.Texture = AddSeparateTranslucencyCompositionPass(GraphBuilder, View, SceneColor.Texture, *Inputs.SeparateTranslucencyTextures);
  485. SceneColorBeforeTonemap = SceneColor;
  486. if (PassSequence.IsEnabled(EPass::Tonemap))
  487. {
  488. FTonemapInputs PassInputs;
  489. PassSequence.AcceptOverrideIfLastPass(EPass::Tonemap, PassInputs.OverrideOutput);
  490. PassInputs.SceneColor = SceneColor;
  491. PassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
  492. PassInputs.bOutputInHDR = bViewFamilyOutputInHDR;
  493. PassInputs.bGammaOnly = true;
  494. SceneColor = AddTonemapPass(GraphBuilder, View, PassInputs);
  495. }
  496. SceneColor = AddAfterPass(EPass::Tonemap, SceneColor);
  497. SceneColorAfterTonemap = SceneColor;
  498. }
  499. if (PassSequence.IsEnabled(EPass::VisualizeStationaryLightOverlap))
  500. {
  501. ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing stationary light overlap."));
  502. FVisualizeComplexityInputs PassInputs;
  503. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeStationaryLightOverlap, PassInputs.OverrideOutput);
  504. PassInputs.SceneColor = OriginalSceneColor;
  505. PassInputs.Colors = GEngine->StationaryLightOverlapColors;
  506. PassInputs.ColorSamplingMethod = FVisualizeComplexityInputs::EColorSamplingMethod::Ramp;
  507. SceneColor = AddVisualizeComplexityPass(GraphBuilder, View, PassInputs);
  508. }
  509. if (PassSequence.IsEnabled(EPass::VisualizeLightCulling))
  510. {
  511. ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing light culling."));
  512. // 0.1f comes from the values used in LightAccumulator_GetResult
  513. const float ComplexityScale = 1.0f / (float)(GEngine->LightComplexityColors.Num() - 1) / 0.1f;
  514. FVisualizeComplexityInputs PassInputs;
  515. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeLightCulling, PassInputs.OverrideOutput);
  516. PassInputs.SceneColor = OriginalSceneColor;
  517. PassInputs.Colors = GEngine->LightComplexityColors;
  518. PassInputs.ColorSamplingMethod = FVisualizeComplexityInputs::EColorSamplingMethod::Linear;
  519. PassInputs.ComplexityScale = ComplexityScale;
  520. SceneColor = AddVisualizeComplexityPass(GraphBuilder, View, PassInputs);
  521. }
  522. if (EngineShowFlags.VisualizeLPV)
  523. {
  524. AddVisualizeLPVPass(GraphBuilder, View, SceneColor);
  525. }
  526. #if WITH_EDITOR
  527. if (PassSequence.IsEnabled(EPass::SelectionOutline))
  528. {
  529. FSelectionOutlineInputs PassInputs;
  530. PassSequence.AcceptOverrideIfLastPass(EPass::SelectionOutline, PassInputs.OverrideOutput);
  531. PassInputs.SceneColor = SceneColor;
  532. PassInputs.SceneDepth = SceneDepth;
  533. PassInputs.SceneTextures.SceneTextures = Inputs.SceneTextures;
  534. SceneColor = AddSelectionOutlinePass(GraphBuilder, View, PassInputs);
  535. }
  536. if (PassSequence.IsEnabled(EPass::EditorPrimitive))
  537. {
  538. FEditorPrimitiveInputs PassInputs;
  539. PassSequence.AcceptOverrideIfLastPass(EPass::EditorPrimitive, PassInputs.OverrideOutput);
  540. PassInputs.SceneColor = SceneColor;
  541. PassInputs.SceneDepth = SceneDepth;
  542. PassInputs.BasePassType = FEditorPrimitiveInputs::EBasePassType::Deferred;
  543. SceneColor = AddEditorPrimitivePass(GraphBuilder, View, PassInputs);
  544. }
  545. #endif
  546. if (PassSequence.IsEnabled(EPass::VisualizeShadingModels))
  547. {
  548. ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing shading models."));
  549. FVisualizeShadingModelInputs PassInputs;
  550. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeShadingModels, PassInputs.OverrideOutput);
  551. PassInputs.SceneColor = SceneColor;
  552. PassInputs.SceneTextures = Inputs.SceneTextures;
  553. SceneColor = AddVisualizeShadingModelPass(GraphBuilder, View, PassInputs);
  554. }
  555. if (PassSequence.IsEnabled(EPass::VisualizeGBufferHints))
  556. {
  557. ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing gbuffer hints."));
  558. FVisualizeGBufferHintsInputs PassInputs;
  559. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeGBufferHints, PassInputs.OverrideOutput);
  560. PassInputs.SceneColor = SceneColor;
  561. PassInputs.OriginalSceneColor = OriginalSceneColor;
  562. PassInputs.SceneTextures = Inputs.SceneTextures;
  563. SceneColor = AddVisualizeGBufferHintsPass(GraphBuilder, View, PassInputs);
  564. }
  565. if (PassSequence.IsEnabled(EPass::VisualizeSubsurface))
  566. {
  567. ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing subsurface."));
  568. FVisualizeSubsurfaceInputs PassInputs;
  569. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeSubsurface, PassInputs.OverrideOutput);
  570. PassInputs.SceneColor = SceneColor;
  571. PassInputs.SceneTextures = Inputs.SceneTextures;
  572. SceneColor = AddVisualizeSubsurfacePass(GraphBuilder, View, PassInputs);
  573. }
  574. if (PassSequence.IsEnabled(EPass::VisualizeGBufferOverview))
  575. {
  576. FVisualizeGBufferOverviewInputs PassInputs;
  577. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeGBufferOverview, PassInputs.OverrideOutput);
  578. PassInputs.SceneColor = SceneColor;
  579. PassInputs.SceneColorBeforeTonemap = SceneColorBeforeTonemap;
  580. PassInputs.SceneColorAfterTonemap = SceneColorAfterTonemap;
  581. PassInputs.SeparateTranslucency = SeparateTranslucency;
  582. PassInputs.Velocity = Velocity;
  583. PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
  584. PassInputs.bOverview = bVisualizeGBufferOverview;
  585. PassInputs.bDumpToFile = bVisualizeGBufferDumpToFile;
  586. PassInputs.bOutputInHDR = bOutputInHDR;
  587. SceneColor = AddVisualizeGBufferOverviewPass(GraphBuilder, View, PassInputs);
  588. }
  589. if (PassSequence.IsEnabled(EPass::VisualizeHDR))
  590. {
  591. FVisualizeHDRInputs PassInputs;
  592. PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeHDR, PassInputs.OverrideOutput);
  593. PassInputs.SceneColor = SceneColor;
  594. PassInputs.SceneColorBeforeTonemap = SceneColorBeforeTonemap;
  595. PassInputs.HistogramTexture = HistogramTexture;
  596. PassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
  597. PassInputs.EyeAdaptationParameters = &EyeAdaptationParameters;
  598. SceneColor = AddVisualizeHDRPass(GraphBuilder, View, PassInputs);
  599. }
  600. #if WITH_EDITOR
  601. if (PassSequence.IsEnabled(EPass::PixelInspector))
  602. {
  603. FPixelInspectorInputs PassInputs;
  604. PassSequence.AcceptOverrideIfLastPass(EPass::PixelInspector, PassInputs.OverrideOutput);
  605. PassInputs.SceneColor = SceneColor;
  606. PassInputs.SceneColorBeforeTonemap = SceneColorBeforeTonemap;
  607. PassInputs.OriginalSceneColor = OriginalSceneColor;
  608. SceneColor = AddPixelInspectorPass(GraphBuilder, View, PassInputs);
  609. }
  610. #endif
  611. if (PassSequence.IsEnabled(EPass::HMDDistortion))
  612. {
  613. FHMDDistortionInputs PassInputs;
  614. PassSequence.AcceptOverrideIfLastPass(EPass::HMDDistortion, PassInputs.OverrideOutput);
  615. PassInputs.SceneColor = SceneColor;
  616. SceneColor = AddHMDDistortionPass(GraphBuilder, View, PassInputs);
  617. }
  618. if (EngineShowFlags.TestImage)
  619. {
  620. AddTestImagePass(GraphBuilder, View, SceneColor);
  621. }
  622. if (ShaderDrawDebug::IsShaderDrawDebugEnabled(View))
  623. {
  624. ShaderDrawDebug::DrawView(GraphBuilder, View, SceneColor.Texture, SceneDepth.Texture);
  625. }
  626. if (ShaderPrint::IsEnabled() && ShaderPrint::IsSupported(View))
  627. {
  628. ShaderPrint::DrawView(GraphBuilder, View, SceneColor.Texture);
  629. }
  630. if (PassSequence.IsEnabled(EPass::HighResolutionScreenshotMask))
  631. {
  632. FHighResolutionScreenshotMaskInputs PassInputs;
  633. PassSequence.AcceptOverrideIfLastPass(EPass::HighResolutionScreenshotMask, PassInputs.OverrideOutput);
  634. PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
  635. PassInputs.SceneColor = SceneColor;
  636. PassInputs.Material = View.FinalPostProcessSettings.HighResScreenshotMaterial;
  637. PassInputs.MaskMaterial = View.FinalPostProcessSettings.HighResScreenshotMaskMaterial;
  638. PassInputs.CaptureRegionMaterial = View.FinalPostProcessSettings.HighResScreenshotCaptureRegionMaterial;
  639. SceneColor = AddHighResolutionScreenshotMaskPass(GraphBuilder, View, PassInputs);
  640. }
  641. if (PassSequence.IsEnabled(EPass::PrimaryUpscale))
  642. {
  643. FUpscaleInputs PassInputs;
  644. PassSequence.AcceptOverrideIfLastPass(EPass::PrimaryUpscale, PassInputs.OverrideOutput);
  645. PassInputs.SceneColor = SceneColor;
  646. PassInputs.Method = GetUpscaleMethod();
  647. PassInputs.Stage = PassSequence.IsEnabled(EPass::SecondaryUpscale) ? EUpscaleStage::PrimaryToSecondary : EUpscaleStage::PrimaryToOutput;
  648. // Panini projection is handled by the primary upscale pass.
  649. PassInputs.PaniniConfig = PaniniConfig;
  650. SceneColor = AddUpscalePass(GraphBuilder, View, PassInputs);
  651. }
  652. if (PassSequence.IsEnabled(EPass::SecondaryUpscale))
  653. {
  654. FUpscaleInputs PassInputs;
  655. PassSequence.AcceptOverrideIfLastPass(EPass::SecondaryUpscale, PassInputs.OverrideOutput);
  656. PassInputs.SceneColor = SceneColor;
  657. PassInputs.Method = View.Family->SecondaryScreenPercentageMethod == ESecondaryScreenPercentageMethod::LowerPixelDensitySimulation ? EUpscaleMethod::SmoothStep : EUpscaleMethod::Nearest;
  658. PassInputs.Stage = EUpscaleStage::SecondaryToOutput;
  659. SceneColor = AddUpscalePass(GraphBuilder, View, PassInputs);
  660. }
  661. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/649850
推荐阅读
相关标签
  

闽ICP备14008679号