diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 8a6dab0..757bdc2 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -315,8 +315,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 955cb66a9ecc20441a7e32934c9b4690, type: 3} m_Name: m_EditorClassIdentifier: - renderScale: 2 - enableJitter: 0 + renderScale: 0.5 + enableJitter: 1 --- !u!114 &963194230 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Fsr2.cs b/Assets/Scripts/Fsr2.cs new file mode 100644 index 0000000..e97a966 --- /dev/null +++ b/Assets/Scripts/Fsr2.cs @@ -0,0 +1,88 @@ +using System; +using UnityEngine; + +namespace FidelityFX +{ + public static class Fsr2 + { + public enum QualityMode + { + Quality = 1, + Balanced = 2, + Performance = 3, + UltraPerformance = 4, + } + + [Flags] + public enum InitializationFlagBits + { + EnableHighDynamicRange = 1 << 0, + EnableDisplayResolutionMotionVectors = 1 << 1, + EnableMotionVectorsJitterCancellation = 1 << 2, + EnableDepthInverted = 1 << 3, + EnableDepthInfinite = 1 << 4, + EnableAutoExposure = 1 << 5, + EnableDynamicResolution = 1 << 6, + EnableTexture1DUsage = 1 << 7, + } + + public static Fsr2Context CreateContext() + { + throw new NotImplementedException(); + } + + public static float GetUpscaleRatioFromQualityMode(QualityMode qualityMode) + { + switch (qualityMode) + { + case QualityMode.Quality: + return 1.5f; + case QualityMode.Balanced: + return 1.7f; + case QualityMode.Performance: + return 2.0f; + case QualityMode.UltraPerformance: + return 3.0f; + default: + return 1.0f; + } + } + + public static void GetRenderResolutionFromQualityMode( + out uint renderWidth, out uint renderHeight, + int displayWidth, int displayHeight, QualityMode qualityMode) + { + float ratio = GetUpscaleRatioFromQualityMode(qualityMode); + renderWidth = (uint)(displayWidth / ratio); + renderHeight = (uint)(displayHeight / ratio); + } + + public static int GetJitterPhaseCount(int renderWidth, int displayWidth) + { + const float basePhaseCount = 8.0f; + int jitterPhaseCount = (int)(basePhaseCount * Mathf.Pow((float)displayWidth / renderWidth, 2.0f)); + return jitterPhaseCount; + } + + public static void GetJitterOffset(out float outX, out float outY, int index, int phaseCount) + { + outX = Halton((index % phaseCount) + 1, 2) - 0.5f; + outY = Halton((index % phaseCount) + 1, 3) - 0.5f; + } + + // Calculate halton number for index and base. + private static float Halton(int index, int @base) + { + float f = 1.0f, result = 0.0f; + + for (int currentIndex = index; currentIndex > 0;) { + + f /= @base; + result += f * (currentIndex % @base); + currentIndex = (int)Mathf.Floor((float)currentIndex / @base); + } + + return result; + } + } +} diff --git a/Assets/Scripts/Fsr2.cs.meta b/Assets/Scripts/Fsr2.cs.meta new file mode 100644 index 0000000..10fe120 --- /dev/null +++ b/Assets/Scripts/Fsr2.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 742d52dc87714f0d93f3b59719859dff +timeCreated: 1673441954 \ No newline at end of file diff --git a/Assets/Scripts/Fsr2Context.cs b/Assets/Scripts/Fsr2Context.cs new file mode 100644 index 0000000..e0ea63e --- /dev/null +++ b/Assets/Scripts/Fsr2Context.cs @@ -0,0 +1,20 @@ +namespace FidelityFX +{ + public class Fsr2Context + { + public void Create() + { + + } + + public void Dispatch() + { + + } + + public void Destroy() + { + + } + } +} diff --git a/Assets/Scripts/Fsr2Context.cs.meta b/Assets/Scripts/Fsr2Context.cs.meta new file mode 100644 index 0000000..ed50468 --- /dev/null +++ b/Assets/Scripts/Fsr2Context.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2f00ea267c3443d88bbd0e9dd7c08b4a +timeCreated: 1673442225 \ No newline at end of file diff --git a/Assets/Scripts/SubsampleTest.cs b/Assets/Scripts/SubsampleTest.cs index 47d9ddb..a95e569 100644 --- a/Assets/Scripts/SubsampleTest.cs +++ b/Assets/Scripts/SubsampleTest.cs @@ -106,8 +106,8 @@ public class SubsampleTest : MonoBehaviour { // Perform custom jittering of the camera's projection matrix according to FSR2's instructions // Unity already does jittering behind the scenes for certain post-effects, so can we perhaps integrate with that? - int jitterPhaseCount = GetJitterPhaseCount(gameCamera.targetTexture.width, Screen.width); - GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount); + int jitterPhaseCount = Fsr2.GetJitterPhaseCount(gameCamera.targetTexture.width, Screen.width); + Fsr2.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount); jitterX = 2.0f * jitterX / gameCamera.targetTexture.width; jitterY = -2.0f * jitterY / gameCamera.targetTexture.height; @@ -122,32 +122,4 @@ public class SubsampleTest : MonoBehaviour gameCamera.rect = tempRect; gameCamera.ResetProjectionMatrix(); } - - private static int GetJitterPhaseCount(int renderWidth, int displayWidth) - { - const float basePhaseCount = 8.0f; - int jitterPhaseCount = (int)(basePhaseCount * Mathf.Pow((float)displayWidth / renderWidth, 2.0f)); - return jitterPhaseCount; - } - - private static void GetJitterOffset(out float outX, out float outY, int index, int phaseCount) - { - outX = Halton((index % phaseCount) + 1, 2) - 0.5f; - outY = Halton((index % phaseCount) + 1, 3) - 0.5f; - } - - // Calculate halton number for index and base. - private static float Halton(int index, int @base) - { - float f = 1.0f, result = 0.0f; - - for (int currentIndex = index; currentIndex > 0;) { - - f /= @base; - result += f * (currentIndex % @base); - currentIndex = (int)Mathf.Floor((float)currentIndex / @base); - } - - return result; - } }