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

Commit

Permalink
UE4.27 + UE5.0 + UE5.1 (#2)
Browse files Browse the repository at this point in the history
* Adjustments to allow using with UE5.1

* Fix shader build

* Adjustments: UE5.1

* Update engine ver. to avoid warning on startup

* Set attribute modifier to be changed only if the file exists to avoid build fails

* Remove engine ver.

* Fix UE5.1 shader compilation w/ D3D12
  • Loading branch information
lucoiso authored Oct 22, 2022
1 parent 6d1cd34 commit 2fcc142
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ enc_temp_folder
*.xcodeproj
*.xcworkspace
*.ipch
*.TMP
*.TMP
Shaders/Private/Version.ush
1 change: 0 additions & 1 deletion FSR.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"EngineVersion": "5.0.0",
"CanContainContent": false,
"Installed": true,
"Modules": [
Expand Down
11 changes: 8 additions & 3 deletions Shaders/Private/PostProcessFFX_HDRColorConversion.usf
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
// THE SOFTWARE.
//------------------------------------------------------------------------------

#include "Version.ush"

#include "/Engine/Private/Common.ush"
#include "/Engine/Private/ScreenPass.ush"


// =====================================================================================
//
// FIDELITYFX SETUP
Expand All @@ -35,7 +36,6 @@
#include "PostProcessFFX_Common.ush"
#include "/Engine/Private/BlueNoise.ush"


#if COMPUTE_SHADER
#ifndef FSR_OUTPUTDEVICE
#error FSR_OUTPUTDEVICE must be defined
Expand Down Expand Up @@ -71,7 +71,12 @@ AF4 ConvertHDRColorToGamma2(AU2 gxy)

AU2 BlueNoiseTileCoord = gxy % BlueNoise.Dimensions.xy; // 256x256
AU1 BlueNoiseSlice = 0;
AF3 PerPixelGrainTex = EvalBlueNoise(BlueNoiseTileCoord, BlueNoiseSlice);

#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
AF3 PerPixelGrainTex = BlueNoiseScalar(BlueNoiseTileCoord, BlueNoiseSlice);
#else
AF3 PerPixelGrainTex = EvalBlueNoise(BlueNoiseTileCoord, BlueNoiseSlice);
#endif

// Temporally Energy Preserving Dither for 10:10:10:2_UNORM / Gamma2 storage
FsrTepdC10F(NormalizedLinearColor, PerPixelGrainTex.r * DitherAmount);
Expand Down
18 changes: 14 additions & 4 deletions Shaders/Private/ffx_a.ush
Original file line number Diff line number Diff line change
Expand Up @@ -2036,10 +2036,20 @@
AF3 AZolSignedF3(AF3 x){return ASatF3(x*AF3_(A_INFN_F));}
AF4 AZolSignedF4(AF4 x){return ASatF4(x*AF4_(A_INFN_F));}
//------------------------------------------------------------------------------------------------------------------------------
AF1 AZolZeroPassF1(AF1 x,AF1 y){return AF1_AU1((AU1_AF1(x)!=AU1_(0))?AU1_(0):AU1_AF1(y));}
AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2_AU2((AU2_AF2(x)!=AU2_(0))?AU2_(0):AU2_AF2(y));}
AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3_AU3((AU3_AF3(x)!=AU3_(0))?AU3_(0):AU3_AF3(y));}
AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4_AU4((AU4_AF4(x)!=AU4_(0))?AU4_(0):AU4_AF4(y));}
#include "Version.ush"

// Fix Shaders compilation in UE5.1 w/ DirectX 12
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
AF1 AZolZeroPassF1(AF1 x,AF1 y){return select(AF1_AU1(AU1_AF1(x)!=AU1_(0)), AU1_(0), AU1_AF1(y));}
AF2 AZolZeroPassF2(AF2 x,AF2 y){return select(AF2_AU2(AU2_AF2(x)!=AU2_(0)), AU2_(0), AU2_AF2(y));}
AF3 AZolZeroPassF3(AF3 x,AF3 y){return select(AF3_AU3(AU3_AF3(x)!=AU3_(0)), AU3_(0), AU3_AF3(y));}
AF4 AZolZeroPassF4(AF4 x,AF4 y){return select(AF4_AU4(AU4_AF4(x)!=AU4_(0)), AU4_(0), AU4_AF4(y));}
#else
AF1 AZolZeroPassF1(AF1 x,AF1 y){return AF1_AU1((AU1_AF1(x)!=AU1_(0))?AU1_(0):AU1_AF1(y));}
AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2_AU2((AU2_AF2(x)!=AU2_(0))?AU2_(0):AU2_AF2(y));}
AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3_AU3((AU3_AF3(x)!=AU3_(0))?AU3_(0):AU3_AF3(y));}
AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4_AU4((AU4_AF4(x)!=AU4_(0))?AU4_(0):AU4_AF4(y));}
#endif
#endif
//==============================================================================================================================
#ifdef A_HALF
Expand Down
15 changes: 14 additions & 1 deletion Source/FSR/FSR.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,18 @@ public FSR(ReadOnlyTargetRules Target) : base(Target)
);

PrecompileForTargets = PrecompileTargetsType.Any;
}

// Some things changed from 4.27 to 5.0 and from 5.0 to 5.1, so we r copying the Version.h to Shaders folder as a .ush file
// To allow adjust the logic of the shaders based on the unreal engine version and this copy will occur when build the plugin
string VersionHeaderPath = System.IO.Path.Combine(EngineDirectory, "Source", "Runtime", "Launch", "Resources", "Version.h");
string DestinationVersionFile = System.IO.Path.Combine(ModuleDirectory, "..", "..", "Shaders", "Private", "Version.ush");

// Version.h is read only by default, we need to uncheck this attribute to allow overwrite the existing Version.ush on copy
if (System.IO.File.Exists(DestinationVersionFile))
{
System.IO.File.SetAttributes(DestinationVersionFile, System.IO.File.GetAttributes(DestinationVersionFile) & ~System.IO.FileAttributes.ReadOnly);
}

System.IO.File.Copy(VersionHeaderPath, DestinationVersionFile, true);
}
}
6 changes: 5 additions & 1 deletion Source/FSR/Private/FSR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ static void LoadEngineTexture(TextureType*& InOutTexture, const TCHAR* InName)
void FFSRModule::StartupModule()
{
FSRViewExtension = FSceneViewExtensions::NewExtension<FFSRViewExtension>();


#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
if (GEngine->BlueNoiseScalarTexture == nullptr)
#else
if (GEngine->BlueNoiseTexture == nullptr)
#endif
{
#if ENGINE_MAJOR_VERSION >= 5
GEngine->LoadBlueNoiseTexture();
Expand Down
76 changes: 75 additions & 1 deletion Source/FSRSpatialUpscaling/Private/Subpasses/FSRSubpassHDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,78 @@
// THE SOFTWARE.
//------------------------------------------------------------------------------
#include "FSRSubpassHDR.h"

#include "BlueNoise.h"

#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
#include "GenericPlatform/GenericPlatformMisc.h"
#endif

static float GFSR_HDR_PQDither = 1.0f;
static FAutoConsoleVariableRef CVarFSR_HDR_PQDither(
TEXT("r.FidelityFX.FSR.HDR.PQDitherAmount"),
GFSR_HDR_PQDither,
TEXT("[HDR-Only] DitherAmount to apply for PQ->Gamma2 conversion to eliminate color banding, when the output device is ST2084/PQ."),
ECVF_RenderThreadSafe);

#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
static EFSR_OutputDevice GetFSROutputDevice(EDisplayOutputFormat UE5DisplayOutputFormat)
{
EFSR_OutputDevice ColorSpace = EFSR_OutputDevice::MAX;

switch (UE5DisplayOutputFormat)
{
case EDisplayOutputFormat::SDR_sRGB:
case EDisplayOutputFormat::SDR_Rec709:
case EDisplayOutputFormat::SDR_ExplicitGammaMapping:
ColorSpace = EFSR_OutputDevice::sRGB;
break;
case EDisplayOutputFormat::HDR_ACES_1000nit_ST2084:
case EDisplayOutputFormat::HDR_ACES_2000nit_ST2084:
ColorSpace = EFSR_OutputDevice::PQ;
break;
case EDisplayOutputFormat::HDR_ACES_1000nit_ScRGB:
case EDisplayOutputFormat::HDR_ACES_2000nit_ScRGB:
ColorSpace = EFSR_OutputDevice::scRGB;
break;
case EDisplayOutputFormat::HDR_LinearEXR:
case EDisplayOutputFormat::HDR_LinearNoToneCurve:
case EDisplayOutputFormat::HDR_LinearWithToneCurve:
ColorSpace = EFSR_OutputDevice::Linear;
break;
}

return ColorSpace;
}

static EFSR_OutputDeviceMaxNits GetOutputDeviceMaxNits(EDisplayOutputFormat eFormat) // only needed for HDR color conversions
{
// this will select shader variants so MAX cannot be used.
EFSR_OutputDeviceMaxNits eMaxNits = EFSR_OutputDeviceMaxNits::EFSR_1000Nits; // Assume 1000 for the default case.

switch (eFormat)
{
case EDisplayOutputFormat::HDR_ACES_1000nit_ST2084:
case EDisplayOutputFormat::HDR_ACES_1000nit_ScRGB:
eMaxNits = EFSR_OutputDeviceMaxNits::EFSR_1000Nits;
break;
case EDisplayOutputFormat::HDR_ACES_2000nit_ST2084:
case EDisplayOutputFormat::HDR_ACES_2000nit_ScRGB:
eMaxNits = EFSR_OutputDeviceMaxNits::EFSR_2000Nits;
break;

case EDisplayOutputFormat::SDR_sRGB:
case EDisplayOutputFormat::SDR_Rec709:
case EDisplayOutputFormat::SDR_ExplicitGammaMapping:
case EDisplayOutputFormat::HDR_LinearEXR:
case EDisplayOutputFormat::HDR_LinearNoToneCurve:
case EDisplayOutputFormat::HDR_LinearWithToneCurve:
default:
// noop
break;
}
return eMaxNits;
}
#else
static EFSR_OutputDevice GetFSROutputDevice(ETonemapperOutputDevice UE4TonemapperOutputDevice)
{
EFSR_OutputDevice ColorSpace = EFSR_OutputDevice::MAX;
Expand Down Expand Up @@ -86,6 +148,7 @@ static EFSR_OutputDeviceMaxNits GetOutputDeviceMaxNits(ETonemapperOutputDevice e
}
return eMaxNits;
}
#endif

//
// COLOR CONVERSION COMPUTE SHADER
Expand Down Expand Up @@ -139,7 +202,12 @@ void FFSRSubpassHDR::ParseEnvironment(FRDGBuilder& GraphBuilder, const FViewInfo
{
Data->TonemapperOutputDeviceParameters = GetTonemapperOutputDeviceParameters(*View.Family);

#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
const EDisplayOutputFormat eTonemapperOutputDevice = (EDisplayOutputFormat)Data->TonemapperOutputDeviceParameters.OutputDevice;
#else
const ETonemapperOutputDevice eTonemapperOutputDevice = (ETonemapperOutputDevice)Data->TonemapperOutputDeviceParameters.OutputDevice;
#endif

Data->eOUTPUT_DEVICE = GetFSROutputDevice(eTonemapperOutputDevice);
Data->eMAX_NITS = GetOutputDeviceMaxNits(eTonemapperOutputDevice);

Expand Down Expand Up @@ -224,8 +292,14 @@ void FFSRSubpassHDR::Upscale(FRDGBuilder& GraphBuilder, const FViewInfo& View, c
FColorConversionCS::FParameters* PassParameters = GraphBuilder.AllocParameters<FColorConversionCS::FParameters>();
PassParameters->InputTexture = Data->CurrentInputTexture;
PassParameters->OutputTexture = GraphBuilder.CreateUAV(Data->ColorConvertedTexture.Texture);

#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
FBlueNoise BlueNoise = GetBlueNoiseParameters();
#else
FBlueNoise BlueNoise;
InitializeBlueNoise(BlueNoise);
#endif

PassParameters->BlueNoise = CreateUniformBufferImmediate(BlueNoise, EUniformBufferUsage::UniformBuffer_SingleFrame);
PassParameters->DitherAmount = FMath::Min(1.0f, FMath::Max(0.0f, GFSR_HDR_PQDither));

Expand Down

0 comments on commit 2fcc142

Please sign in to comment.