Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessVisualizeLocalExposure.cpp
tiago costa a074a8e460 Local Exposure using Bilaterial Grid based Contrast Reduction.
- Image exposure is locally adjusted by decomposing luminance of the frame into a base layer and a detail layer.
- Base layer contrast can be reduced while preserving detail.
- Support blending with gaussian blurred luminance as proposed in Advances in Real-Time Rendering in Games 2021.
- Controls in PostProcessVolume.
- r.LocalExposure cvar to control whether local exposure is supported.
- Visualization mode in "Show->Visualize->Local Expsoure". Multiple modes controllable using r.LocalExposure.VisualizeDebugMode.
- Bilateral grid generation not yet optimized. Optimization should include increasing depth of grid to match histogram size so that global histogram can be generated from grid.
- Added option to use mirror address mode in PostProcessWeightedSampleSum, since black border adds noticeable vignetting to the blurred luminance.

#preflight 612f65169db3090001ba3eec
#rb Brian.Karis, Guillaume.Abadie, Krzysztof.Narkowicz


#ROBOMERGE-SOURCE: CL 17385317
#ROBOMERGE-BOT: (v865-17346139)

[CL 17387198 by tiago costa in ue5-main branch]
2021-09-01 11:20:37 -04:00

91 lines
3.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "PostProcess/PostProcessVisualizeLocalExposure.h"
#include "PostProcess/PostProcessTonemap.h"
#include "UnrealEngine.h"
TAutoConsoleVariable<int> CVarLocalExposureVisualizeDebugMode(
TEXT("r.LocalExposure.VisualizeDebugMode"),
0,
TEXT("When enabling Show->Visualize->Local Exposure is enabled, this flag controls which mode to use.\n")
TEXT(" 0: Local Exposure\n")
TEXT(" 1: Base Luminance\n")
TEXT(" 2: Detail Luminance\n"),
ECVF_RenderThreadSafe);
class FVisualizeLocalExposurePS : public FGlobalShader
{
public:
DECLARE_GLOBAL_SHADER(FVisualizeLocalExposurePS);
SHADER_USE_PARAMETER_STRUCT(FVisualizeLocalExposurePS, FGlobalShader);
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, View)
SHADER_PARAMETER_STRUCT(FEyeAdaptationParameters, EyeAdaptation)
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Input)
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Output)
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, HDRSceneColorTexture)
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, EyeAdaptationTexture)
SHADER_PARAMETER_RDG_TEXTURE(Texture3D, LumBilateralGrid)
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, BlurredLogLum)
SHADER_PARAMETER_SAMPLER(SamplerState, TextureSampler)
SHADER_PARAMETER(uint32, DebugMode)
RENDER_TARGET_BINDING_SLOTS()
END_SHADER_PARAMETER_STRUCT()
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5);
}
};
IMPLEMENT_GLOBAL_SHADER(FVisualizeLocalExposurePS, "/Engine/Private/PostProcessVisualizeLocalExposure.usf", "MainPS", SF_Pixel);
FScreenPassTexture AddVisualizeLocalExposurePass(FRDGBuilder& GraphBuilder, const FViewInfo& View, const FVisualizeLocalExposureInputs& Inputs)
{
check(Inputs.SceneColor.IsValid());
check(Inputs.HDRSceneColor.IsValid());
check(Inputs.LumBilateralGridTexture);
check(Inputs.BlurredLumTexture);
check(Inputs.EyeAdaptationTexture);
check(Inputs.EyeAdaptationParameters);
FScreenPassRenderTarget Output = Inputs.OverrideOutput;
if (!Output.IsValid())
{
Output = FScreenPassRenderTarget::CreateFromInput(GraphBuilder, Inputs.SceneColor, View.GetOverwriteLoadAction(), TEXT("VisualizeLocalExposure"));
}
const FScreenPassTextureViewport InputViewport(Inputs.SceneColor);
const FScreenPassTextureViewport OutputViewport(Output);
FRHISamplerState* BilinearClampSampler = TStaticSamplerState<SF_Bilinear, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
const FPostProcessSettings& Settings = View.FinalPostProcessSettings;
auto PassParameters = GraphBuilder.AllocParameters<FVisualizeLocalExposurePS::FParameters>();
PassParameters->RenderTargets[0] = Output.GetRenderTargetBinding();
PassParameters->View = View.ViewUniformBuffer;
PassParameters->EyeAdaptation = *Inputs.EyeAdaptationParameters;
PassParameters->Input = GetScreenPassTextureViewportParameters(InputViewport);
PassParameters->Output = GetScreenPassTextureViewportParameters(OutputViewport);
PassParameters->HDRSceneColorTexture = Inputs.HDRSceneColor.Texture;
PassParameters->EyeAdaptationTexture = Inputs.EyeAdaptationTexture;
PassParameters->LumBilateralGrid = Inputs.LumBilateralGridTexture;
PassParameters->BlurredLogLum = Inputs.BlurredLumTexture;
PassParameters->TextureSampler = BilinearClampSampler;
PassParameters->DebugMode = CVarLocalExposureVisualizeDebugMode.GetValueOnRenderThread();
TShaderMapRef<FVisualizeLocalExposurePS> PixelShader(View.ShaderMap);
RDG_EVENT_SCOPE(GraphBuilder, "VisualizeLocalExposure");
AddDrawScreenPass(GraphBuilder, RDG_EVENT_NAME("Visualizer"), View, OutputViewport, InputViewport, PixelShader, PassParameters);
return MoveTemp(Output);
}