Browse Source
Reorganization: created new class for main FSR2 entry points, enums and helper functions. Created a stub Fsr2Context class. Moved jitter helper functions into main FSR2 class. Translated a couple more helper functions.
mac-autoexp
Reorganization: created new class for main FSR2 entry points, enums and helper functions. Created a stub Fsr2Context class. Moved jitter helper functions into main FSR2 class. Translated a couple more helper functions.
mac-autoexp
6 changed files with 118 additions and 32 deletions
-
4Assets/Scenes/SampleScene.unity
-
88Assets/Scripts/Fsr2.cs
-
3Assets/Scripts/Fsr2.cs.meta
-
20Assets/Scripts/Fsr2Context.cs
-
3Assets/Scripts/Fsr2Context.cs.meta
-
32Assets/Scripts/SubsampleTest.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; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 742d52dc87714f0d93f3b59719859dff |
|||
timeCreated: 1673441954 |
|||
@ -0,0 +1,20 @@ |
|||
namespace FidelityFX |
|||
{ |
|||
public class Fsr2Context |
|||
{ |
|||
public void Create() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public void Dispatch() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public void Destroy() |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 2f00ea267c3443d88bbd0e9dd7c08b4a |
|||
timeCreated: 1673442225 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue