Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessAA.cpp
guillaume abadie eadb45ef37 Replaces r.PostProcessAAQuality with r.FXAA.Quality & r.TemporalAA.Quality
Now only r.AntiAliasingMethod prevails to selects the anti-aliasing method explicitly for the deferred shading renderer. Each AA technic have it's own cvars to control their quality independently

FXAA now have its own r.FXAA.Quality. The FXAA shader permutations where mis configured with r.PostProcessAAQuality=1 & 2 both mapping to the FXAA_PC_CONSOLE=1 that is now r.FXAA.Quality=0. Instead r.FXAA.Quality now offer more mid-quality settings for FXAA_PC=1 with r.FXAA.Quality=1 & 2 & 3. Backward comaptible migration is as followed:
- r.AntiAliasingMethod=1 r.PostProcessAAQuality=0 -> r.FXAA.Quality=0
- r.AntiAliasingMethod=1 r.PostProcessAAQuality=1 -> r.FXAA.Quality=0
- r.AntiAliasingMethod=1 r.PostProcessAAQuality=2 -> r.FXAA.Quality=0
- r.AntiAliasingMethod=1 r.PostProcessAAQuality=3 -> r.FXAA.Quality=3 but with some neighborhood search setting changed in FXAAShader.usf
- r.AntiAliasingMethod=1 r.PostProcessAAQuality=4 -> r.FXAA.Quality=4
- r.AntiAliasingMethod=1 r.PostProcessAAQuality=5 -> r.FXAA.Quality=5

TAA now have its own r.TemporalAA.Quality. Backward compatible migration is as followed:
- r.AntiAliasingMethod=2 r.PostProcessAAQuality=0 -> r.AntiAliasingMethod=0
- r.AntiAliasingMethod=2 r.PostProcessAAQuality=1 -> r.AntiAliasingMethod=1 r.FXAA.Quality=0
- r.AntiAliasingMethod=2 r.PostProcessAAQuality=2 -> r.AntiAliasingMethod=1 r.FXAA.Quality=0
- r.AntiAliasingMethod=2 r.PostProcessAAQuality=3 r.TemporalAAUpsampleFiltered=0 -> r.TemporalAA.Quality=0
- r.AntiAliasingMethod=2 r.PostProcessAAQuality=3 r.TemporalAAUpsampleFiltered=1 -> r.TemporalAA.Quality=1
- r.AntiAliasingMethod=2 r.PostProcessAAQuality=4 -> r.TemporalAA.Quality=2

MSAA r.AntiAliasingMethod=3 & TSR r.AntiAliasingMethod=4 remains unchanged.

sg.AntiAliasingQuality now maps to different r.TemporalAA.Quality or r.FXAA.Quality

Automated tests on base CL: https://horde.devtools.epicgames.com/job/60d5b8410123b700014f9db5
Automated tests on change CL: https://horde.devtools.epicgames.com/job/60d47cde57b302000114bebf

#rb none
[FYI] jack.porter, wei.liu
#lockdown michal.valient

#ROBOMERGE-SOURCE: CL 16823623 via CL 16823646
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v836-16769935)

[CL 16823657 by guillaume abadie in ue5-release-engine-test branch]
2021-07-12 07:13:12 -04:00

134 lines
4.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "PostProcess/PostProcessAA.h"
#include "PostProcess/PostProcessing.h"
TAutoConsoleVariable<int32> CVarFXAAQuality(
TEXT("r.FXAA.Quality"), 4,
TEXT("Selects the quality permutation of FXAA.\n")
TEXT(" 0: Console\n")
TEXT(" 1: PC medium-dither 3-sample\n")
TEXT(" 2: PC medium-dither 5-sample\n")
TEXT(" 3: PC medium-dither 8-sample\n")
TEXT(" 4: PC low-dither 12-sample (Default)\n")
TEXT(" 5: PC extrem quality 12-samples"),
ECVF_Scalability | ECVF_RenderThreadSafe);
BEGIN_SHADER_PARAMETER_STRUCT(FFXAAParameters, )
SHADER_PARAMETER_STRUCT(FScreenPassTextureInput, Input)
SHADER_PARAMETER(FVector4, fxaaConsoleRcpFrameOpt)
SHADER_PARAMETER(FVector4, fxaaConsoleRcpFrameOpt2)
SHADER_PARAMETER(float, fxaaQualitySubpix)
SHADER_PARAMETER(float, fxaaQualityEdgeThreshold)
SHADER_PARAMETER(float, fxaaQualityEdgeThresholdMin)
SHADER_PARAMETER(float, fxaaConsoleEdgeSharpness)
SHADER_PARAMETER(float, fxaaConsoleEdgeThreshold)
SHADER_PARAMETER(float, fxaaConsoleEdgeThresholdMin)
RENDER_TARGET_BINDING_SLOTS()
END_SHADER_PARAMETER_STRUCT()
class FFXAAVS : public FGlobalShader
{
public:
DECLARE_GLOBAL_SHADER(FFXAAVS);
// FDrawRectangleParameters is filled by DrawScreenPass.
SHADER_USE_PARAMETER_STRUCT_WITH_LEGACY_BASE(FFXAAVS, FGlobalShader);
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
return true;
}
using FParameters = FFXAAParameters;
};
IMPLEMENT_GLOBAL_SHADER(FFXAAVS, "/Engine/Private/FXAAShader.usf", "FxaaVS", SF_Vertex);
class FFXAAPS : public FGlobalShader
{
public:
DECLARE_GLOBAL_SHADER(FFXAAPS);
SHADER_USE_PARAMETER_STRUCT(FFXAAPS, FGlobalShader);
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
return true;
}
class FQualityDimension : SHADER_PERMUTATION_ENUM_CLASS("FXAA_PRESET", EFXAAQuality);
using FPermutationDomain = TShaderPermutationDomain<FQualityDimension>;
using FParameters = FFXAAParameters;
};
IMPLEMENT_GLOBAL_SHADER(FFXAAPS, "/Engine/Private/FXAAShader.usf", "FxaaPS", SF_Pixel);
EFXAAQuality GetFXAAQuality()
{
return EFXAAQuality(FMath::Clamp(CVarFXAAQuality.GetValueOnRenderThread(), 0, 5));
}
FScreenPassTexture AddFXAAPass(FRDGBuilder& GraphBuilder, const FViewInfo& View, const FFXAAInputs& Inputs)
{
check(Inputs.SceneColor.IsValid());
check(Inputs.Quality != EFXAAQuality::MAX);
FScreenPassRenderTarget Output = Inputs.OverrideOutput;
if (!Output.IsValid())
{
Output = FScreenPassRenderTarget::CreateFromInput(GraphBuilder, Inputs.SceneColor, View.GetOverwriteLoadAction(), TEXT("FXAA"));
}
const FVector2D OutputExtentInverse = FVector2D(1.0f / (float)Output.Texture->Desc.Extent.X, 1.0f / (float)Output.Texture->Desc.Extent.Y);
FRHISamplerState* BilinearClampSampler = TStaticSamplerState<SF_Bilinear, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
FFXAAParameters* PassParameters = GraphBuilder.AllocParameters<FFXAAParameters>();
PassParameters->RenderTargets[0] = Output.GetRenderTargetBinding();
PassParameters->Input = GetScreenPassTextureInput(Inputs.SceneColor, BilinearClampSampler);
{
float N = 0.5f;
FVector4 Value(-N * OutputExtentInverse.X, -N * OutputExtentInverse.Y, N * OutputExtentInverse.X, N * OutputExtentInverse.Y);
PassParameters->fxaaConsoleRcpFrameOpt = Value;
}
{
float N = 2.0f;
FVector4 Value(-N * OutputExtentInverse.X, -N * OutputExtentInverse.Y, N * OutputExtentInverse.X, N * OutputExtentInverse.Y);
PassParameters->fxaaConsoleRcpFrameOpt2 = Value;
}
PassParameters->fxaaQualitySubpix = 0.75f;
PassParameters->fxaaQualityEdgeThreshold = 0.166f;
PassParameters->fxaaQualityEdgeThresholdMin = 0.0833f;
PassParameters->fxaaConsoleEdgeSharpness = 8.0f;
PassParameters->fxaaConsoleEdgeThreshold = 0.125f;
PassParameters->fxaaConsoleEdgeThresholdMin = 0.05f;
FFXAAPS::FPermutationDomain PixelPermutationVector;
PixelPermutationVector.Set<FFXAAPS::FQualityDimension>(Inputs.Quality);
TShaderMapRef<FFXAAVS> VertexShader(View.ShaderMap);
TShaderMapRef<FFXAAPS> PixelShader(View.ShaderMap, PixelPermutationVector);
const FScreenPassTextureViewport OutputViewport(Output);
AddDrawScreenPass(
GraphBuilder,
RDG_EVENT_NAME("FXAA(Quality=%d) %dx%d PS", Inputs.Quality, OutputViewport.Rect.Width(), OutputViewport.Rect.Height()),
View,
OutputViewport,
FScreenPassTextureViewport(Inputs.SceneColor),
FScreenPassPipelineState(VertexShader, PixelShader),
PassParameters,
EScreenPassDrawFlags::AllowHMDHiddenAreaMask,
[VertexShader, PixelShader, PassParameters](FRHICommandList& RHICmdList)
{
SetShaderParameters(RHICmdList, VertexShader, VertexShader.GetVertexShader(), *PassParameters);
SetShaderParameters(RHICmdList, PixelShader, PixelShader.GetPixelShader(), *PassParameters);
});
return MoveTemp(Output);
}