赞
踩
GEngine\Source\Runtime\Renderer\Private\DeferredShadingRenderer.cpp
FDeferredShadingSceneRenderer::Render()
- // Finish rendering for each view.
- if (ViewFamily.bResolveScene && ViewFamilyTexture)
- {
- RDG_EVENT_SCOPE(GraphBuilder, "PostProcessing");
- RDG_GPU_STAT_SCOPE(GraphBuilder, Postprocessing);
- SCOPE_CYCLE_COUNTER(STAT_FinishRenderViewTargetTime);
-
- AddSetCurrentStatPass(GraphBuilder, GET_STATID(STAT_CLM_PostProcessing));
-
- FPostProcessingInputs PostProcessingInputs;
- PostProcessingInputs.ViewFamilyTexture = ViewFamilyTexture;
- PostProcessingInputs.SeparateTranslucencyTextures = &SeparateTranslucencyTextures;
- PostProcessingInputs.SceneTextures = SceneTextures;
-
- if (ViewFamily.UseDebugViewPS())
- {
- for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
- {
- const FViewInfo& View = Views[ViewIndex];
- RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
- RDG_EVENT_SCOPE_CONDITIONAL(GraphBuilder, Views.Num() > 1, "View%d", ViewIndex);
- AddDebugViewPostProcessingPasses(GraphBuilder, View, PostProcessingInputs);
- }
- }
- else
- {
- for (int32 ViewExt = 0; ViewExt < ViewFamily.ViewExtensions.Num(); ++ViewExt)
- {
- for (int32 ViewIndex = 0; ViewIndex < ViewFamily.Views.Num(); ++ViewIndex)
- {
- FViewInfo& View = Views[ViewIndex];
- RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
- ViewFamily.ViewExtensions[ViewExt]->PrePostProcessPass_RenderThread(GraphBuilder, View, PostProcessingInputs);
- }
- }
- for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
- {
- const FViewInfo& View = Views[ViewIndex];
- RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
- RDG_EVENT_SCOPE_CONDITIONAL(GraphBuilder, Views.Num() > 1, "View%d", ViewIndex);
-
- #if !(UE_BUILD_SHIPPING)
- if (IsPostProcessVisualizeCalibrationMaterialEnabled(View))
- {
- const UMaterialInterface* DebugMaterialInterface = GetPostProcessVisualizeCalibrationMaterialInterface(View);
- check(DebugMaterialInterface);
-
- AddVisualizeCalibrationMaterialPostProcessingPasses(GraphBuilder, View, PostProcessingInputs, DebugMaterialInterface);
- }
- else
- #endif
- {
- AddPostProcessingPasses(GraphBuilder, View, PostProcessingInputs);
- }
- }
- }
-
- AddPass(GraphBuilder, [this, &SceneContext](FRHICommandListImmediate&)
- {
- SceneContext.SetSceneColor(nullptr);
- });
- }
\Engine\Source\Runtime\Renderer\Private\PostProcess\PostProcessing.cpp
- void AddPostProcessingPasses(FRDGBuilder& GraphBuilder, const FViewInfo& View, const FPostProcessingInputs& Inputs)
- {
- RDG_CSV_STAT_EXCLUSIVE_SCOPE(GraphBuilder, RenderPostProcessing);
- QUICK_SCOPE_CYCLE_COUNTER(STAT_PostProcessing_Process);
-
- check(IsInRenderingThread());
- check(View.VerifyMembersChecks());
- Inputs.Validate();
-
- 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 SeparateTranslucency(Inputs.SeparateTranslucencyTextures->GetColorForRead(GraphBuilder), PrimaryViewRect);
- const FScreenPassTexture CustomDepth((*Inputs.SceneTextures)->CustomDepthTexture, PrimaryViewRect);
- const FScreenPassTexture Velocity(SceneTextureParameters.GBufferVelocityTexture, PrimaryViewRect);
- const FScreenPassTexture BlackDummy(GSystemTextures.GetBlackDummy(GraphBuilder));
-
- // Scene color is updated incrementally through the post process pipeline.
- FScreenPassTexture SceneColor((*Inputs.SceneTextures)->SceneColorTexture, PrimaryViewRect);
-
- // Assigned before and after the tonemapper.
- FScreenPassTexture SceneColorBeforeTonemap;
- FScreenPassTexture SceneColorAfterTonemap;
-
- // Unprocessed scene color stores the original input.
- const FScreenPassTexture OriginalSceneColor = SceneColor;
-
- // Default the new eye adaptation to the last one in case it's not generated this frame.
- const FEyeAdaptationParameters EyeAdaptationParameters = GetEyeAdaptationParameters(View, ERHIFeatureLevel::SM5);
- FRDGTextureRef LastEyeAdaptationTexture = GetEyeAdaptationTexture(GraphBuilder, View);
- FRDGTextureRef EyeAdaptationTexture = LastEyeAdaptationTexture;
-
- // Histogram defaults to black because the histogram eye adaptation pass is used for the manual metering mode.
- FRDGTextureRef HistogramTexture = BlackDummy.Texture;
-
- const FEngineShowFlags& EngineShowFlags = View.Family->EngineShowFlags;
- const bool bVisualizeHDR = EngineShowFlags.VisualizeHDR;
- const bool bViewFamilyOutputInHDR = GRHISupportsHDROutput && IsHDREnabled();
- const bool bVisualizeGBufferOverview = IsVisualizeGBufferOverviewEnabled(View);
- const bool bVisualizeGBufferDumpToFile = IsVisualizeGBufferDumpToFileEnabled(View);
- const bool bVisualizeGBufferDumpToPIpe = IsVisualizeGBufferDumpToPipeEnabled(View);
- const bool bOutputInHDR = IsPostProcessingOutputInHDR();
-
- const FPaniniProjectionConfig PaniniConfig(View);
-
- enum class EPass : uint32
- {
- MotionBlur,
- Tonemap,
- FXAA,
- PostProcessMaterialAfterTonemapping,
- VisualizeDepthOfField,
- VisualizeStationaryLightOverlap,
- VisualizeLightCulling,
- SelectionOutline,
- EditorPrimitive,
- VisualizeShadingModels,
- VisualizeGBufferHints,
- VisualizeSubsurface,
- VisualizeGBufferOverview,
- VisualizeHDR,
- PixelInspector,
- HMDDistortion,
- HighResolutionScreenshotMask,
- PrimaryUpscale,
- SecondaryUpscale,
- MAX
- };
-
- const auto TranslatePass = [](ISceneViewExtension::EPostProcessingPass Pass) -> EPass
- {
- switch (Pass)
- {
- case ISceneViewExtension::EPostProcessingPass::MotionBlur : return EPass::MotionBlur;
- case ISceneViewExtension::EPostProcessingPass::Tonemap : return EPass::Tonemap;
- case ISceneViewExtension::EPostProcessingPass::FXAA : return EPass::FXAA;
- case ISceneViewExtension::EPostProcessingPass::VisualizeDepthOfField : return EPass::VisualizeDepthOfField;
-
- default:
- check(false);
- return EPass::MAX;
- };
- };
-
- const TCHAR* PassNames[] =
- {
- TEXT("MotionBlur"),
- TEXT("Tonemap"),
- TEXT("FXAA"),
- TEXT("PostProcessMaterial (AfterTonemapping)"),
- TEXT("VisualizeDepthOfField"),
- TEXT("VisualizeStationaryLightOverlap"),
- TEXT("VisualizeLightCulling"),
- TEXT("SelectionOutline"),
- TEXT("EditorPrimitive"),
- TEXT("VisualizeShadingModels"),
- TEXT("VisualizeGBufferHints"),
- TEXT("VisualizeSubsurface"),
- TEXT("VisualizeGBufferOverview"),
- TEXT("VisualizeHDR"),
- TEXT("PixelInspector"),
- TEXT("HMDDistortion"),
- TEXT("HighResolutionScreenshotMask"),
- TEXT("PrimaryUpscale"),
- TEXT("SecondaryUpscale")
- };
-
- static_assert(static_cast<uint32>(EPass::MAX) == UE_ARRAY_COUNT(PassNames), "EPass does not match PassNames.");
-
- TOverridePassSequence<EPass> PassSequence(ViewFamilyOutput);
- PassSequence.SetNames(PassNames, UE_ARRAY_COUNT(PassNames));
- PassSequence.SetEnabled(EPass::VisualizeStationaryLightOverlap, EngineShowFlags.StationaryLightOverlap);
- PassSequence.SetEnabled(EPass::VisualizeLightCulling, EngineShowFlags.VisualizeLightCulling);
- #if WITH_EDITOR
- PassSequence.SetEnabled(EPass::SelectionOutline, GIsEditor && EngineShowFlags.Selection && EngineShowFlags.SelectionOutline && !EngineShowFlags.Wireframe && !bVisualizeHDR && !IStereoRendering::IsStereoEyeView(View));
- PassSequence.SetEnabled(EPass::EditorPrimitive, FSceneRenderer::ShouldCompositeEditorPrimitives(View));
- #else
- PassSequence.SetEnabled(EPass::SelectionOutline, false);
- PassSequence.SetEnabled(EPass::EditorPrimitive, false);
- #endif
- PassSequence.SetEnabled(EPass::VisualizeShadingModels, EngineShowFlags.VisualizeShadingModels);
- PassSequence.SetEnabled(EPass::VisualizeGBufferHints, EngineShowFlags.GBufferHints);
- PassSequence.SetEnabled(EPass::VisualizeSubsurface, EngineShowFlags.VisualizeSSS);
- PassSequence.SetEnabled(EPass::VisualizeGBufferOverview, bVisualizeGBufferOverview || bVisualizeGBufferDumpToFile || bVisualizeGBufferDumpToPIpe);
- PassSequence.SetEnabled(EPass::VisualizeHDR, EngineShowFlags.VisualizeHDR);
- #if WITH_EDITOR
- PassSequence.SetEnabled(EPass::PixelInspector, View.bUsePixelInspector);
- #else
- PassSequence.SetEnabled(EPass::PixelInspector, false);
- #endif
- PassSequence.SetEnabled(EPass::HMDDistortion, EngineShowFlags.StereoRendering && EngineShowFlags.HMDDistortion);
- PassSequence.SetEnabled(EPass::HighResolutionScreenshotMask, IsHighResolutionScreenshotMaskEnabled(View));
- PassSequence.SetEnabled(EPass::PrimaryUpscale, PaniniConfig.IsEnabled() || (View.PrimaryScreenPercentageMethod == EPrimaryScreenPercentageMethod::SpatialUpscale && PrimaryViewRect.Size() != View.GetSecondaryViewRectSize()));
- PassSequence.SetEnabled(EPass::SecondaryUpscale, View.RequiresSecondaryUpscale());
-
- const auto GetPostProcessMaterialInputs = [&](FScreenPassTexture InSceneColor)
- {
- FPostProcessMaterialInputs PostProcessMaterialInputs;
-
- PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::SceneColor, InSceneColor);
- PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::SeparateTranslucency, SeparateTranslucency);
- PostProcessMaterialInputs.SetInput(EPostProcessMaterialInput::Velocity, Velocity);
- PostProcessMaterialInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
- PostProcessMaterialInputs.CustomDepthTexture = CustomDepth.Texture;
-
- return PostProcessMaterialInputs;
- };
-
- const auto AddAfterPass = [&](EPass InPass, FScreenPassTexture InSceneColor) -> FScreenPassTexture
- {
- // In some cases (e.g. OCIO color conversion) we want View Extensions to be able to add extra custom post processing after the pass.
-
- FAfterPassCallbackDelegateArray& PassCallbacks = PassSequence.GetAfterPassCallbacks(InPass);
-
- if (PassCallbacks.Num())
- {
- FPostProcessMaterialInputs InOutPostProcessAfterPassInputs = GetPostProcessMaterialInputs(InSceneColor);
-
- for (int32 AfterPassCallbackIndex = 0; AfterPassCallbackIndex < PassCallbacks.Num(); AfterPassCallbackIndex++)
- {
- FAfterPassCallbackDelegate& AfterPassCallback = PassCallbacks[AfterPassCallbackIndex];
- PassSequence.AcceptOverrideIfLastPass(InPass, InOutPostProcessAfterPassInputs.OverrideOutput, AfterPassCallbackIndex);
- InSceneColor = AfterPassCallback.Execute(GraphBuilder, View, InOutPostProcessAfterPassInputs);
- }
- }
-
- return MoveTemp(InSceneColor);
- };
-
- if (IsPostProcessingEnabled(View))
- {
- const EStereoscopicPass StereoPass = View.StereoPass;
- const bool bPrimaryView = IStereoRendering::IsAPrimaryView(View);
- const bool bHasViewState = View.ViewState != nullptr;
- const bool bDepthOfFieldEnabled = DiaphragmDOF::IsEnabled(View);
- const bool bVisualizeDepthOfField = bDepthOfFieldEnabled && EngineShowFlags.VisualizeDOF;
- const bool bVisualizeMotionBlur = IsVisualizeMotionBlurEnabled(View);
-
- const EAutoExposureMethod AutoExposureMethod = GetAutoExposureMethod(View);
- const EAntiAliasingMethod AntiAliasingMethod = !bVisualizeDepthOfField ? View.AntiAliasingMethod : AAM_None;
- const EDownsampleQuality DownsampleQuality = GetDownsampleQuality();
- const EPixelFormat DownsampleOverrideFormat = PF_FloatRGB;
-
- // Motion blur gets replaced by the visualization pass.
- const bool bMotionBlurEnabled = !bVisualizeMotionBlur && IsMotionBlurEnabled(View);
-
- // Skip tonemapping for visualizers which overwrite the HDR scene color.
- const bool bTonemapEnabled = !bVisualizeMotionBlur;
- const bool bTonemapOutputInHDR = View.Family->SceneCaptureSource == SCS_FinalColorHDR || View.Family->SceneCaptureSource == SCS_FinalToneCurveHDR || bOutputInHDR || bViewFamilyOutputInHDR;
-
- // We don't test for the EyeAdaptation engine show flag here. If disabled, the auto exposure pass is still executes but performs a clamp.
- const bool bEyeAdaptationEnabled =
- // Skip for transient views.
- bHasViewState &&
- // Skip for secondary views in a stereo setup.
- bPrimaryView;
-
- const bool bHistogramEnabled =
- // Force the histogram on when we are visualizing HDR.
- bVisualizeHDR ||
- // Skip if not using histogram eye adaptation.
- (bEyeAdaptationEnabled && AutoExposureMethod == EAutoExposureMethod::AEM_Histogram &&
- // Skip if we don't have any exposure range to generate (eye adaptation will clamp).
- View.FinalPostProcessSettings.AutoExposureMinBrightness < View.FinalPostProcessSettings.AutoExposureMaxBrightness);
-
- const bool bBloomEnabled = View.FinalPostProcessSettings.BloomIntensity > 0.0f;
-
- const FPostProcessMaterialChain PostProcessMaterialAfterTonemappingChain = GetPostProcessMaterialChain(View, BL_AfterTonemapping);
-
- PassSequence.SetEnabled(EPass::MotionBlur, bVisualizeMotionBlur || bMotionBlurEnabled);
- PassSequence.SetEnabled(EPass::Tonemap, bTonemapEnabled);
- PassSequence.SetEnabled(EPass::FXAA, AntiAliasingMethod == AAM_FXAA);
- PassSequence.SetEnabled(EPass::PostProcessMaterialAfterTonemapping, PostProcessMaterialAfterTonemappingChain.Num() != 0);
- PassSequence.SetEnabled(EPass::VisualizeDepthOfField, bVisualizeDepthOfField);
-
- for (int32 ViewExt = 0; ViewExt < View.Family->ViewExtensions.Num(); ++ViewExt)
- {
- for (int32 SceneViewPassId = 0; SceneViewPassId != static_cast<int>(ISceneViewExtension::EPostProcessingPass::MAX); SceneViewPassId++)
- {
- ISceneViewExtension::EPostProcessingPass SceneViewPass = static_cast<ISceneViewExtension::EPostProcessingPass>(SceneViewPassId);
- EPass PostProcessingPass = TranslatePass(SceneViewPass);
-
- View.Family->ViewExtensions[ViewExt]->SubscribeToPostProcessingPass(
- SceneViewPass,
- PassSequence.GetAfterPassCallbacks(PostProcessingPass),
- PassSequence.IsEnabled(PostProcessingPass));
- }
- }
-
- PassSequence.Finalize();
-
- // Post Process Material Chain - Before Translucency
- {
- const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_BeforeTranslucency);
-
- if (MaterialChain.Num())
- {
- SceneColor = AddPostProcessMaterialChain(GraphBuilder, View, GetPostProcessMaterialInputs(SceneColor), MaterialChain);
- }
- }
-
- // Diaphragm Depth of Field
- {
- FRDGTextureRef LocalSceneColorTexture = SceneColor.Texture;
-
- if (bDepthOfFieldEnabled)
- {
- LocalSceneColorTexture = DiaphragmDOF::AddPasses(GraphBuilder, SceneTextureParameters, View, SceneColor.Texture, *Inputs.SeparateTranslucencyTextures);
- }
-
- // DOF passes were not added, therefore need to compose Separate translucency manually.
- if (LocalSceneColorTexture == SceneColor.Texture)
- {
- LocalSceneColorTexture = AddSeparateTranslucencyCompositionPass(GraphBuilder, View, SceneColor.Texture, *Inputs.SeparateTranslucencyTextures);
- }
-
- SceneColor.Texture = LocalSceneColorTexture;
- }
-
- // Post Process Material Chain - Before Tonemapping
- {
- const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_BeforeTonemapping);
-
- if (MaterialChain.Num())
- {
- SceneColor = AddPostProcessMaterialChain(GraphBuilder, View, GetPostProcessMaterialInputs(SceneColor), MaterialChain);
- }
- }
-
- FScreenPassTexture HalfResolutionSceneColor;
-
- // Scene color view rectangle after temporal AA upscale to secondary screen percentage.
- FIntRect SecondaryViewRect = PrimaryViewRect;
-
- // Temporal Anti-aliasing. Also may perform a temporal upsample from primary to secondary view rect.
- if (AntiAliasingMethod == AAM_TemporalAA)
- {
- // Whether we allow the temporal AA pass to downsample scene color. It may choose not to based on internal context,
- // in which case the output half resolution texture will remain null.
- const bool bAllowSceneDownsample =
- IsTemporalAASceneDownsampleAllowed(View) &&
- // We can only merge if the normal downsample pass would happen immediately after.
- !bMotionBlurEnabled && !bVisualizeMotionBlur &&
- // TemporalAA is only able to match the low quality mode (box filter).
- GetDownsampleQuality() == EDownsampleQuality::Low;
-
-
- int32 UpscaleMode = ITemporalUpscaler::GetTemporalUpscalerMode();
-
- const ITemporalUpscaler* DefaultTemporalUpscaler = ITemporalUpscaler::GetDefaultTemporalUpscaler();
- const ITemporalUpscaler* UpscalerToUse = ( UpscaleMode == 0 || !View.Family->GetTemporalUpscalerInterface())? DefaultTemporalUpscaler : View.Family->GetTemporalUpscalerInterface();
-
- const TCHAR* UpscalerName = UpscalerToUse->GetDebugName();
-
- // Standard event scope for temporal upscaler to have all profiling information not matter what, and with explicit detection of third party.
- RDG_EVENT_SCOPE_CONDITIONAL(
- GraphBuilder,
- UpscalerToUse != DefaultTemporalUpscaler,
- "ThirdParty %s %dx%d -> %dx%d",
- UpscalerToUse->GetDebugName(),
- View.ViewRect.Width(), View.ViewRect.Height(),
- View.GetSecondaryViewRectSize().X, View.GetSecondaryViewRectSize().Y);
-
- ITemporalUpscaler::FPassInputs UpscalerPassInputs;
-
- UpscalerPassInputs.bAllowDownsampleSceneColor = bAllowSceneDownsample;
- UpscalerPassInputs.DownsampleOverrideFormat = DownsampleOverrideFormat;
- UpscalerPassInputs.SceneColorTexture = SceneColor.Texture;
- UpscalerPassInputs.SceneDepthTexture = SceneDepth.Texture;
- UpscalerPassInputs.SceneVelocityTexture = Velocity.Texture;
- UpscalerPassInputs.EyeAdaptationTexture = GetEyeAdaptationTexture(GraphBuilder, View);
-
- UpscalerToUse->AddPasses(
- GraphBuilder,
- View,
- UpscalerPassInputs,
- &SceneColor.Texture,
- &SecondaryViewRect,
- &HalfResolutionSceneColor.Texture,
- &HalfResolutionSceneColor.ViewRect);
- }
- else if (ShouldRenderScreenSpaceReflections(View))
- {
- // If we need SSR, and TAA is enabled, then AddTemporalAAPass() has already handled the scene history.
- // If we need SSR, and TAA is not enable, then we just need to extract the history.
- if (!View.bStatePrevViewInfoIsReadOnly)
- {
- check(View.ViewState);
- FTemporalAAHistory& OutputHistory = View.ViewState->PrevFrameViewInfo.TemporalAAHistory;
- GraphBuilder.QueueTextureExtraction(SceneColor.Texture, &OutputHistory.RT[0]);
-
- // For SSR, we still fill up the rest of the OutputHistory data using shared math from FTAAPassParameters.
- FTAAPassParameters TAAInputs(View);
- TAAInputs.SceneColorInput = SceneColor.Texture;
- TAAInputs.SetupViewRect(View);
- OutputHistory.ViewportRect = TAAInputs.OutputViewRect;
- OutputHistory.ReferenceBufferSize = TAAInputs.GetOutputExtent() * TAAInputs.ResolutionDivisor;
- }
- }
-
- //! SceneColorTexture is now upsampled to the SecondaryViewRect. Use SecondaryViewRect for input / output.
- SceneColor.ViewRect = SecondaryViewRect;
-
- // Post Process Material Chain - SSR Input
- if (View.ViewState && !View.bStatePrevViewInfoIsReadOnly)
- {
- const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_SSRInput);
-
- if (MaterialChain.Num())
- {
- // Save off SSR post process output for the next frame.
- FScreenPassTexture PassOutput = AddPostProcessMaterialChain(GraphBuilder, View, GetPostProcessMaterialInputs(SceneColor), MaterialChain);
- GraphBuilder.QueueTextureExtraction(PassOutput.Texture, &View.ViewState->PrevFrameViewInfo.CustomSSRInput);
- }
- }
-
- if (PassSequence.IsEnabled(EPass::MotionBlur))
- {
- FMotionBlurInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::MotionBlur, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneDepth = SceneDepth;
- PassInputs.SceneVelocity = Velocity;
- PassInputs.Quality = GetMotionBlurQuality();
- PassInputs.Filter = GetMotionBlurFilter();
-
- // Motion blur visualization replaces motion blur when enabled.
- if (bVisualizeMotionBlur)
- {
- SceneColor = AddVisualizeMotionBlurPass(GraphBuilder, View, PassInputs);
- }
- else
- {
- SceneColor = AddMotionBlurPass(GraphBuilder, View, PassInputs);
- }
- }
-
- SceneColor = AddAfterPass(EPass::MotionBlur, SceneColor);
-
- // If TAA didn't do it, downsample the scene color texture by half.
- if (!HalfResolutionSceneColor.Texture)
- {
- FDownsamplePassInputs PassInputs;
- PassInputs.Name = TEXT("HalfResolutionSceneColor");
- PassInputs.SceneColor = SceneColor;
- PassInputs.Quality = DownsampleQuality;
- PassInputs.FormatOverride = DownsampleOverrideFormat;
-
- HalfResolutionSceneColor = AddDownsamplePass(GraphBuilder, View, PassInputs);
- }
-
- // Store half res scene color in the history
- extern int32 GSSRHalfResSceneColor;
- if (ShouldRenderScreenSpaceReflections(View) && !View.bStatePrevViewInfoIsReadOnly && GSSRHalfResSceneColor)
- {
- check(View.ViewState);
- GraphBuilder.QueueTextureExtraction(HalfResolutionSceneColor.Texture, &View.ViewState->PrevFrameViewInfo.HalfResTemporalAAHistory);
- }
-
- FSceneDownsampleChain SceneDownsampleChain;
-
- if (bHistogramEnabled)
- {
- HistogramTexture = AddHistogramPass(GraphBuilder, View, EyeAdaptationParameters, HalfResolutionSceneColor, LastEyeAdaptationTexture);
- }
-
- if (bEyeAdaptationEnabled)
- {
- const bool bBasicEyeAdaptationEnabled = bEyeAdaptationEnabled && (AutoExposureMethod == EAutoExposureMethod::AEM_Basic);
-
- if (bBasicEyeAdaptationEnabled)
- {
- const bool bLogLumaInAlpha = true;
- SceneDownsampleChain.Init(GraphBuilder, View, EyeAdaptationParameters, HalfResolutionSceneColor, DownsampleQuality, bLogLumaInAlpha);
-
- // Use the alpha channel in the last downsample (smallest) to compute eye adaptations values.
- EyeAdaptationTexture = AddBasicEyeAdaptationPass(GraphBuilder, View, EyeAdaptationParameters, SceneDownsampleChain.GetLastTexture(), LastEyeAdaptationTexture);
- }
- // Add histogram eye adaptation pass even if no histogram exists to support the manual clamping mode.
- else
- {
- EyeAdaptationTexture = AddHistogramEyeAdaptationPass(GraphBuilder, View, EyeAdaptationParameters, HistogramTexture);
- }
- }
-
- FScreenPassTexture Bloom;
-
- if (bBloomEnabled)
- {
- FSceneDownsampleChain BloomDownsampleChain;
-
- FBloomInputs PassInputs;
- PassInputs.SceneColor = SceneColor;
-
- const bool bBloomThresholdEnabled = View.FinalPostProcessSettings.BloomThreshold > -1.0f;
-
- // Reuse the main scene downsample chain if a threshold isn't required for bloom.
- if (SceneDownsampleChain.IsInitialized() && !bBloomThresholdEnabled)
- {
- PassInputs.SceneDownsampleChain = &SceneDownsampleChain;
- }
- else
- {
- FScreenPassTexture DownsampleInput = HalfResolutionSceneColor;
-
- if (bBloomThresholdEnabled)
- {
- const float BloomThreshold = View.FinalPostProcessSettings.BloomThreshold;
-
- FBloomSetupInputs SetupPassInputs;
- SetupPassInputs.SceneColor = DownsampleInput;
- SetupPassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
- SetupPassInputs.Threshold = BloomThreshold;
-
- DownsampleInput = AddBloomSetupPass(GraphBuilder, View, SetupPassInputs);
- }
-
- const bool bLogLumaInAlpha = false;
- BloomDownsampleChain.Init(GraphBuilder, View, EyeAdaptationParameters, DownsampleInput, DownsampleQuality, bLogLumaInAlpha);
-
- PassInputs.SceneDownsampleChain = &BloomDownsampleChain;
- }
-
- FBloomOutputs PassOutputs = AddBloomPass(GraphBuilder, View, PassInputs);
- SceneColor = PassOutputs.SceneColor;
- Bloom = PassOutputs.Bloom;
-
- FScreenPassTexture LensFlares = AddLensFlaresPass(GraphBuilder, View, Bloom, *PassInputs.SceneDownsampleChain);
-
- if (LensFlares.IsValid())
- {
- // Lens flares are composited with bloom.
- Bloom = LensFlares;
- }
- }
-
- // Tonemapper needs a valid bloom target, even if it's black.
- if (!Bloom.IsValid())
- {
- Bloom = BlackDummy;
- }
-
- SceneColorBeforeTonemap = SceneColor;
-
- if (PassSequence.IsEnabled(EPass::Tonemap))
- {
- const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_ReplacingTonemapper);
-
- if (MaterialChain.Num())
- {
- const UMaterialInterface* HighestPriorityMaterial = MaterialChain[0];
-
- FPostProcessMaterialInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::Tonemap, PassInputs.OverrideOutput);
- PassInputs.SetInput(EPostProcessMaterialInput::SceneColor, SceneColor);
- PassInputs.SetInput(EPostProcessMaterialInput::SeparateTranslucency, SeparateTranslucency);
- PassInputs.SetInput(EPostProcessMaterialInput::CombinedBloom, Bloom);
- PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
- PassInputs.CustomDepthTexture = CustomDepth.Texture;
-
- SceneColor = AddPostProcessMaterialPass(GraphBuilder, View, PassInputs, HighestPriorityMaterial);
- }
- else
- {
- FRDGTextureRef ColorGradingTexture = nullptr;
-
- if (bPrimaryView)
- {
- ColorGradingTexture = AddCombineLUTPass(GraphBuilder, View);
- }
- // We can re-use the color grading texture from the primary view.
- else if (View.GetTonemappingLUT())
- {
- ColorGradingTexture = TryRegisterExternalTexture(GraphBuilder, View.GetTonemappingLUT());
- }
- else
- {
- const FViewInfo* PrimaryView = static_cast<const FViewInfo*>(View.Family->Views[0]);
- ColorGradingTexture = TryRegisterExternalTexture(GraphBuilder, PrimaryView->GetTonemappingLUT());
- }
-
- FTonemapInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::Tonemap, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.Bloom = Bloom;
- PassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
- PassInputs.ColorGradingTexture = ColorGradingTexture;
- PassInputs.bWriteAlphaChannel = AntiAliasingMethod == AAM_FXAA || IsPostProcessingWithAlphaChannelSupported();
- PassInputs.bOutputInHDR = bTonemapOutputInHDR;
-
- SceneColor = AddTonemapPass(GraphBuilder, View, PassInputs);
- }
- }
-
- SceneColor = AddAfterPass(EPass::Tonemap, SceneColor);
-
- SceneColorAfterTonemap = SceneColor;
-
- if (PassSequence.IsEnabled(EPass::FXAA))
- {
- FFXAAInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::FXAA, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.Quality = GetFXAAQuality();
-
- SceneColor = AddFXAAPass(GraphBuilder, View, PassInputs);
- }
-
- SceneColor = AddAfterPass(EPass::FXAA, SceneColor);
-
- // Post Process Material Chain - After Tonemapping
- if (PassSequence.IsEnabled(EPass::PostProcessMaterialAfterTonemapping))
- {
- FPostProcessMaterialInputs PassInputs = GetPostProcessMaterialInputs(SceneColor);
- PassSequence.AcceptOverrideIfLastPass(EPass::PostProcessMaterialAfterTonemapping, PassInputs.OverrideOutput);
- PassInputs.SetInput(EPostProcessMaterialInput::PreTonemapHDRColor, SceneColorBeforeTonemap);
- PassInputs.SetInput(EPostProcessMaterialInput::PostTonemapHDRColor, SceneColorAfterTonemap);
- PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
-
- SceneColor = AddPostProcessMaterialChain(GraphBuilder, View, PassInputs, PostProcessMaterialAfterTonemappingChain);
- }
-
- if (PassSequence.IsEnabled(EPass::VisualizeDepthOfField))
- {
- FVisualizeDOFInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeDepthOfField, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneDepth = SceneDepth;
-
- SceneColor = AddVisualizeDOFPass(GraphBuilder, View, PassInputs);
- }
-
- SceneColor = AddAfterPass(EPass::VisualizeDepthOfField, SceneColor);
- }
- // Minimal PostProcessing - Separate translucency composition and gamma-correction only.
- else
- {
- PassSequence.SetEnabled(EPass::MotionBlur, false);
- PassSequence.SetEnabled(EPass::Tonemap, true);
- PassSequence.SetEnabled(EPass::FXAA, false);
- PassSequence.SetEnabled(EPass::PostProcessMaterialAfterTonemapping, false);
- PassSequence.SetEnabled(EPass::VisualizeDepthOfField, false);
- PassSequence.Finalize();
-
- SceneColor.Texture = AddSeparateTranslucencyCompositionPass(GraphBuilder, View, SceneColor.Texture, *Inputs.SeparateTranslucencyTextures);
-
- SceneColorBeforeTonemap = SceneColor;
-
- if (PassSequence.IsEnabled(EPass::Tonemap))
- {
- FTonemapInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::Tonemap, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
- PassInputs.bOutputInHDR = bViewFamilyOutputInHDR;
- PassInputs.bGammaOnly = true;
-
- SceneColor = AddTonemapPass(GraphBuilder, View, PassInputs);
- }
-
- SceneColor = AddAfterPass(EPass::Tonemap, SceneColor);
-
- SceneColorAfterTonemap = SceneColor;
- }
-
- if (PassSequence.IsEnabled(EPass::VisualizeStationaryLightOverlap))
- {
- ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing stationary light overlap."));
-
- FVisualizeComplexityInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeStationaryLightOverlap, PassInputs.OverrideOutput);
- PassInputs.SceneColor = OriginalSceneColor;
- PassInputs.Colors = GEngine->StationaryLightOverlapColors;
- PassInputs.ColorSamplingMethod = FVisualizeComplexityInputs::EColorSamplingMethod::Ramp;
-
- SceneColor = AddVisualizeComplexityPass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::VisualizeLightCulling))
- {
- ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing light culling."));
-
- // 0.1f comes from the values used in LightAccumulator_GetResult
- const float ComplexityScale = 1.0f / (float)(GEngine->LightComplexityColors.Num() - 1) / 0.1f;
-
- FVisualizeComplexityInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeLightCulling, PassInputs.OverrideOutput);
- PassInputs.SceneColor = OriginalSceneColor;
- PassInputs.Colors = GEngine->LightComplexityColors;
- PassInputs.ColorSamplingMethod = FVisualizeComplexityInputs::EColorSamplingMethod::Linear;
- PassInputs.ComplexityScale = ComplexityScale;
-
- SceneColor = AddVisualizeComplexityPass(GraphBuilder, View, PassInputs);
- }
-
- if (EngineShowFlags.VisualizeLPV)
- {
- AddVisualizeLPVPass(GraphBuilder, View, SceneColor);
- }
-
- #if WITH_EDITOR
- if (PassSequence.IsEnabled(EPass::SelectionOutline))
- {
- FSelectionOutlineInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::SelectionOutline, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneDepth = SceneDepth;
- PassInputs.SceneTextures.SceneTextures = Inputs.SceneTextures;
-
- SceneColor = AddSelectionOutlinePass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::EditorPrimitive))
- {
- FEditorPrimitiveInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::EditorPrimitive, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneDepth = SceneDepth;
- PassInputs.BasePassType = FEditorPrimitiveInputs::EBasePassType::Deferred;
-
- SceneColor = AddEditorPrimitivePass(GraphBuilder, View, PassInputs);
- }
- #endif
-
- if (PassSequence.IsEnabled(EPass::VisualizeShadingModels))
- {
- ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing shading models."));
-
- FVisualizeShadingModelInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeShadingModels, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneTextures = Inputs.SceneTextures;
-
- SceneColor = AddVisualizeShadingModelPass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::VisualizeGBufferHints))
- {
- ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing gbuffer hints."));
-
- FVisualizeGBufferHintsInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeGBufferHints, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.OriginalSceneColor = OriginalSceneColor;
- PassInputs.SceneTextures = Inputs.SceneTextures;
-
- SceneColor = AddVisualizeGBufferHintsPass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::VisualizeSubsurface))
- {
- ensureMsgf(View.PrimaryScreenPercentageMethod != EPrimaryScreenPercentageMethod::TemporalUpscale, TEXT("TAAU should be disabled when visualizing subsurface."));
-
- FVisualizeSubsurfaceInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeSubsurface, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneTextures = Inputs.SceneTextures;
-
- SceneColor = AddVisualizeSubsurfacePass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::VisualizeGBufferOverview))
- {
- FVisualizeGBufferOverviewInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeGBufferOverview, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneColorBeforeTonemap = SceneColorBeforeTonemap;
- PassInputs.SceneColorAfterTonemap = SceneColorAfterTonemap;
- PassInputs.SeparateTranslucency = SeparateTranslucency;
- PassInputs.Velocity = Velocity;
- PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
- PassInputs.bOverview = bVisualizeGBufferOverview;
- PassInputs.bDumpToFile = bVisualizeGBufferDumpToFile;
- PassInputs.bOutputInHDR = bOutputInHDR;
-
- SceneColor = AddVisualizeGBufferOverviewPass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::VisualizeHDR))
- {
- FVisualizeHDRInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::VisualizeHDR, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneColorBeforeTonemap = SceneColorBeforeTonemap;
- PassInputs.HistogramTexture = HistogramTexture;
- PassInputs.EyeAdaptationTexture = EyeAdaptationTexture;
- PassInputs.EyeAdaptationParameters = &EyeAdaptationParameters;
-
- SceneColor = AddVisualizeHDRPass(GraphBuilder, View, PassInputs);
- }
-
- #if WITH_EDITOR
- if (PassSequence.IsEnabled(EPass::PixelInspector))
- {
- FPixelInspectorInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::PixelInspector, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.SceneColorBeforeTonemap = SceneColorBeforeTonemap;
- PassInputs.OriginalSceneColor = OriginalSceneColor;
-
- SceneColor = AddPixelInspectorPass(GraphBuilder, View, PassInputs);
- }
- #endif
-
- if (PassSequence.IsEnabled(EPass::HMDDistortion))
- {
- FHMDDistortionInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::HMDDistortion, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
-
- SceneColor = AddHMDDistortionPass(GraphBuilder, View, PassInputs);
- }
-
- if (EngineShowFlags.TestImage)
- {
- AddTestImagePass(GraphBuilder, View, SceneColor);
- }
-
- if (ShaderDrawDebug::IsShaderDrawDebugEnabled(View))
- {
- ShaderDrawDebug::DrawView(GraphBuilder, View, SceneColor.Texture, SceneDepth.Texture);
- }
- if (ShaderPrint::IsEnabled() && ShaderPrint::IsSupported(View))
- {
- ShaderPrint::DrawView(GraphBuilder, View, SceneColor.Texture);
- }
-
- if (PassSequence.IsEnabled(EPass::HighResolutionScreenshotMask))
- {
- FHighResolutionScreenshotMaskInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::HighResolutionScreenshotMask, PassInputs.OverrideOutput);
- PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
- PassInputs.SceneColor = SceneColor;
- PassInputs.Material = View.FinalPostProcessSettings.HighResScreenshotMaterial;
- PassInputs.MaskMaterial = View.FinalPostProcessSettings.HighResScreenshotMaskMaterial;
- PassInputs.CaptureRegionMaterial = View.FinalPostProcessSettings.HighResScreenshotCaptureRegionMaterial;
-
- SceneColor = AddHighResolutionScreenshotMaskPass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::PrimaryUpscale))
- {
- FUpscaleInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::PrimaryUpscale, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.Method = GetUpscaleMethod();
- PassInputs.Stage = PassSequence.IsEnabled(EPass::SecondaryUpscale) ? EUpscaleStage::PrimaryToSecondary : EUpscaleStage::PrimaryToOutput;
-
- // Panini projection is handled by the primary upscale pass.
- PassInputs.PaniniConfig = PaniniConfig;
-
- SceneColor = AddUpscalePass(GraphBuilder, View, PassInputs);
- }
-
- if (PassSequence.IsEnabled(EPass::SecondaryUpscale))
- {
- FUpscaleInputs PassInputs;
- PassSequence.AcceptOverrideIfLastPass(EPass::SecondaryUpscale, PassInputs.OverrideOutput);
- PassInputs.SceneColor = SceneColor;
- PassInputs.Method = View.Family->SecondaryScreenPercentageMethod == ESecondaryScreenPercentageMethod::LowerPixelDensitySimulation ? EUpscaleMethod::SmoothStep : EUpscaleMethod::Nearest;
- PassInputs.Stage = EUpscaleStage::SecondaryToOutput;
-
- SceneColor = AddUpscalePass(GraphBuilder, View, PassInputs);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。