Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Update and adjust the plugin to allow using with both UE4 and UE5
Browse files Browse the repository at this point in the history
  • Loading branch information
lucoiso committed Jul 20, 2022
1 parent 8b7d1ce commit 6d1cd34
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 3 deletions.
2 changes: 1 addition & 1 deletion FSR.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"EngineVersion": "5.0",
"EngineVersion": "5.0.0",
"CanContainContent": false,
"Installed": true,
"Modules": [
Expand Down
8 changes: 7 additions & 1 deletion Source/FSR/Private/FSR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include "Engine/Engine.h"
#include "Engine/Texture2D.h"

static_assert((ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION == 27 && ENGINE_PATCH_VERSION >= 1) || (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 27) || ENGINE_MAJOR_VERSION >= 5, "FSR plugin requires UE4.27.1 or greater.");
static_assert((ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION == 27 && ENGINE_PATCH_VERSION >= 1)
|| (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 27)
|| ENGINE_MAJOR_VERSION >= 5, "FSR plugin requires UE4.27.1 or greater.");

IMPLEMENT_MODULE(FFSRModule, FSR)

Expand Down Expand Up @@ -56,7 +58,11 @@ void FFSRModule::StartupModule()

if (GEngine->BlueNoiseTexture == nullptr)
{
#if ENGINE_MAJOR_VERSION >= 5
GEngine->LoadBlueNoiseTexture();
#else
LoadEngineTexture(GEngine->BlueNoiseTexture, *GEngine->BlueNoiseTextureName.ToString());
#endif
}
}

Expand Down
1 change: 1 addition & 0 deletions Source/FSRSpatialUpscaling/FSRSpatialUpscaling.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public FSRSpatialUpscaling(ReadOnlyTargetRules Target) : base(Target)
PublicDependencyModuleNames.AddRange(
new string[]
{

// ... add other public dependencies that you statically link with here ...
}
);
Expand Down
13 changes: 12 additions & 1 deletion Source/FSRSpatialUpscaling/Private/FSRViewExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void FFSRViewExtension::BeginRenderViewFamily(FSceneViewFamily& InViewFamily)
{
// if we are in the full Editor, don't let the DPI-upscaler interfere with FSR
static auto CVarEnableEditorScreenPercentageOverride = IConsoleManager::Get().FindConsoleVariable(TEXT("Editor.OverrideDPIBasedEditorViewportScaling"));

if (CVarEnableEditorScreenPercentageOverride != nullptr)
{
CVarEnableEditorScreenPercentageOverride->Set(1);
Expand All @@ -77,8 +77,14 @@ void FFSRViewExtension::BeginRenderViewFamily(FSceneViewFamily& InViewFamily)

// TSharedPtr will clean up this allocation
FFSRData* Data = new FFSRData();

#if ENGINE_MAJOR_VERSION >= 5
Data->PostProcess_GrainIntensity = InView->FinalPostProcessSettings.GrainIntensity_DEPRECATED;
Data->PostProcess_GrainJitter = InView->FinalPostProcessSettings.GrainJitter_DEPRECATED;
#else
Data->PostProcess_GrainIntensity = InView->FinalPostProcessSettings.GrainIntensity;
Data->PostProcess_GrainJitter = InView->FinalPostProcessSettings.GrainJitter;
#endif
Data->PostProcess_SceneFringeIntensity = InView->FinalPostProcessSettings.SceneFringeIntensity;
Data->PostProcess_ChromaticAberrationStartOffset = InView->FinalPostProcessSettings.ChromaticAberrationStartOffset;
ViewData.Add(TSharedPtr<FFSRData>(Data));
Expand Down Expand Up @@ -107,8 +113,13 @@ void FFSRViewExtension::PreRenderView_RenderThread(FRHICommandListImmediate& RHI
if (IsFilmGrainPassEnabled())
{
// setting these values to 0 completely disables the shader permutations in PostProcessTonemap. it doesn't just run it with no visible result.
#if ENGINE_MAJOR_VERSION >= 5
InView.FinalPostProcessSettings.GrainIntensity_DEPRECATED = 0;
InView.FinalPostProcessSettings.GrainJitter_DEPRECATED = 0;
#else
InView.FinalPostProcessSettings.GrainIntensity = 0;
InView.FinalPostProcessSettings.GrainJitter = 0;
#endif
}

if (IsChromaticAberrationPassEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ static FVector4 GetChromaticAberrationParameters(const FPostProcessSettings& Pos
// this section copy-pasted from PostProcessTonemap.cpp to re-generate Color Fringe parameters ----------------
return ChromaticAberrationParams;
}

#if ENGINE_MAJOR_VERSION >= 5
static void GetLensParameters(FVector4f& LensPrincipalPointOffsetScale, FVector4f& LensPrincipalPointOffsetScaleInverse, const FViewInfo& View)
#else
static void GetLensParameters(FVector4& LensPrincipalPointOffsetScale, FVector4& LensPrincipalPointOffsetScaleInverse, const FViewInfo& View)
#endif
{
// this section copy-pasted from PostProcessTonemap.cpp to re-generate Color Fringe parameters ----------------
LensPrincipalPointOffsetScale = View.LensPrincipalPointOffsetScale;
Expand Down Expand Up @@ -100,9 +105,17 @@ class FChromaticAberrationPS : public FGlobalShader
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, ColorTexture)
SHADER_PARAMETER_SAMPLER(SamplerState, ColorSampler)

#if ENGINE_MAJOR_VERSION >= 5
SHADER_PARAMETER(FVector4f, ChromaticAberrationParams)
SHADER_PARAMETER(FVector4f, LensPrincipalPointOffsetScale)
SHADER_PARAMETER(FVector4f, LensPrincipalPointOffsetScaleInverse)
#else
SHADER_PARAMETER(FVector4, ChromaticAberrationParams)
SHADER_PARAMETER(FVector4, LensPrincipalPointOffsetScale)
SHADER_PARAMETER(FVector4, LensPrincipalPointOffsetScaleInverse)
#endif

SHADER_PARAMETER_STRUCT_INCLUDE(FFSRPassParameters_Grain, FilmGrain)
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Color)
RENDER_TARGET_BINDING_SLOTS()
Expand Down Expand Up @@ -136,9 +149,17 @@ class FChromaticAberrationCS : public FGlobalShader
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, ColorTexture)
SHADER_PARAMETER_SAMPLER(SamplerState, ColorSampler)

#if ENGINE_MAJOR_VERSION >= 5
SHADER_PARAMETER(FVector4f, ChromaticAberrationParams)
SHADER_PARAMETER(FVector4f, LensPrincipalPointOffsetScale)
SHADER_PARAMETER(FVector4f, LensPrincipalPointOffsetScaleInverse)
#else
SHADER_PARAMETER(FVector4, ChromaticAberrationParams)
SHADER_PARAMETER(FVector4, LensPrincipalPointOffsetScale)
SHADER_PARAMETER(FVector4, LensPrincipalPointOffsetScaleInverse)
#endif

SHADER_PARAMETER_STRUCT_INCLUDE(FFSRPassParameters_Grain, FilmGrain)
SHADER_PARAMETER_STRUCT(FScreenPassTextureViewportParameters, Color)
SHADER_PARAMETER_RDG_TEXTURE_UAV(RWTexture2D, OutputTexture)
Expand Down Expand Up @@ -220,7 +241,13 @@ void FFSRSubpassChromaticAberration::PostProcess(FRDGBuilder& GraphBuilder, cons
PassParameters->ColorSampler = BilinearClampSampler;
PassParameters->RenderTargets[0] = FRenderTargetBinding(Output.Texture, ERenderTargetLoadAction::ENoAction);
PassParameters->Color = GetScreenPassTextureViewportParameters(FScreenPassTextureViewport(PassParameters->ColorTexture));

#if ENGINE_MAJOR_VERSION >= 5
PassParameters->ChromaticAberrationParams = FVector4f(GetChromaticAberrationParameters(Data->ChromaticAberrationPostProcessSettings));
#else
PassParameters->ChromaticAberrationParams = GetChromaticAberrationParameters(Data->ChromaticAberrationPostProcessSettings);
#endif

PassParameters->FilmGrain = Data->FilmGrainParams;
GetLensParameters(PassParameters->LensPrincipalPointOffsetScale, PassParameters->LensPrincipalPointOffsetScaleInverse, View);

Expand Down Expand Up @@ -253,9 +280,16 @@ void FFSRSubpassChromaticAberration::PostProcess(FRDGBuilder& GraphBuilder, cons
PassParameters->ColorTexture = Data->CurrentInputTexture;
PassParameters->ColorSampler = BilinearClampSampler;
PassParameters->Color = GetScreenPassTextureViewportParameters(FScreenPassTextureViewport(PassParameters->ColorTexture));

#if ENGINE_MAJOR_VERSION >= 5
PassParameters->ChromaticAberrationParams = FVector4f(GetChromaticAberrationParameters(Data->ChromaticAberrationPostProcessSettings));
#else
PassParameters->ChromaticAberrationParams = GetChromaticAberrationParameters(Data->ChromaticAberrationPostProcessSettings);
#endif

PassParameters->OutputTexture = GraphBuilder.CreateUAV(Output.Texture);
PassParameters->FilmGrain = Data->FilmGrainParams;

GetLensParameters(PassParameters->LensPrincipalPointOffsetScale, PassParameters->LensPrincipalPointOffsetScaleInverse, View);

FChromaticAberrationCS::FPermutationDomain CSPermutationVector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ static TAutoConsoleVariable<int32> CVarFSRPostFSRFilmGrain(
static FFSRPassParameters_Grain GetFilmGrainParameters(const FViewInfo& View, const float GrainIntensity, const float GrainJitter)
{
// this section copy-pasted from PostProcessTonemap.cpp (with modifications) to re-generate Grain Intensity parameters ----------------
#if ENGINE_MAJOR_VERSION >= 5
FVector3f GrainRandomFullValue;
#else
FVector GrainRandomFullValue;
#endif
{
uint8 FrameIndexMod8 = 0;
if (View.Family)
Expand All @@ -51,8 +55,15 @@ static FFSRPassParameters_Grain GetFilmGrainParameters(const FViewInfo& View, co
// this section copy-pasted from PostProcessTonemap.cpp (with modifications) to re-generate Grain Intensity parameters ----------------

FFSRPassParameters_Grain Parameters;

#if ENGINE_MAJOR_VERSION >= 5
Parameters.GrainRandomFull = FVector4f(GrainRandomFullValue.X, GrainRandomFullValue.Y, 0, 0);
Parameters.GrainScaleBiasJitter = FVector4f(GrainScaleBiasJitter.X, GrainScaleBiasJitter.Y, GrainScaleBiasJitter.Z, 0);
#else
Parameters.GrainRandomFull = FVector4(GrainRandomFullValue.X, GrainRandomFullValue.Y, 0, 0);
Parameters.GrainScaleBiasJitter = FVector4(GrainScaleBiasJitter, 0);
#endif

return Parameters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ class FRCAS_DenoiseDim : SHADER_PERMUTATION_BOOL("USE_RCAS_DENOISE");
// SHADER PASS PARAMETERS
//
BEGIN_SHADER_PARAMETER_STRUCT(FFSRPassParameters_Grain, )
#if ENGINE_MAJOR_VERSION >= 5
SHADER_PARAMETER(FVector4f, GrainRandomFull)
SHADER_PARAMETER(FVector4f, GrainScaleBiasJitter)
#else
SHADER_PARAMETER(FVector4, GrainRandomFull)
SHADER_PARAMETER(FVector4, GrainScaleBiasJitter)
#endif
END_SHADER_PARAMETER_STRUCT()

BEGIN_SHADER_PARAMETER_STRUCT(FFSRPassParameters, )
Expand All @@ -87,8 +92,15 @@ BEGIN_SHADER_PARAMETER_STRUCT(FFSRPassParameters, )
SHADER_PARAMETER(FUintVector4, Const2)
SHADER_PARAMETER(FUintVector4, Const3)
SHADER_PARAMETER_STRUCT_INCLUDE(FFSRPassParameters_Grain, FilmGrain)

#if ENGINE_MAJOR_VERSION >= 5
SHADER_PARAMETER(FVector2f, VPColor_ExtentInverse)
SHADER_PARAMETER(FVector2f, VPColor_ViewportMin)
#else
SHADER_PARAMETER(FVector2D, VPColor_ExtentInverse)
SHADER_PARAMETER(FVector2D, VPColor_ViewportMin)
#endif

SHADER_PARAMETER_SAMPLER(SamplerState, samLinearClamp)
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InputTexture)
END_SHADER_PARAMETER_STRUCT()
Expand All @@ -97,5 +109,10 @@ BEGIN_SHADER_PARAMETER_STRUCT(FRCASPassParameters, )
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InputTexture)
SHADER_PARAMETER(FUintVector4, Const0)
SHADER_PARAMETER_STRUCT_INCLUDE(FFSRPassParameters_Grain, FilmGrain)

#if ENGINE_MAJOR_VERSION >= 5
SHADER_PARAMETER(FVector2f, VPColor_ExtentInverse)
#else
SHADER_PARAMETER(FVector2D, VPColor_ExtentInverse)
#endif
END_SHADER_PARAMETER_STRUCT()

1 comment on commit 6d1cd34

@lucoiso
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.