diff --git a/Assets/Resources/Shaders/FSR2CopyDepth.shader b/Assets/Resources/Shaders/FSR2_CopyDepth.shader similarity index 100% rename from Assets/Resources/Shaders/FSR2CopyDepth.shader rename to Assets/Resources/Shaders/FSR2_CopyDepth.shader diff --git a/Assets/Resources/Shaders/FSR2CopyDepth.shader.meta b/Assets/Resources/Shaders/FSR2_CopyDepth.shader.meta similarity index 100% rename from Assets/Resources/Shaders/FSR2CopyDepth.shader.meta rename to Assets/Resources/Shaders/FSR2_CopyDepth.shader.meta diff --git a/Assets/Resources/Shaders/FSR2CopyMotionVectors.shader b/Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader similarity index 100% rename from Assets/Resources/Shaders/FSR2CopyMotionVectors.shader rename to Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader diff --git a/Assets/Resources/Shaders/FSR2CopyMotionVectors.shader.meta b/Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader.meta similarity index 100% rename from Assets/Resources/Shaders/FSR2CopyMotionVectors.shader.meta rename to Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader.meta diff --git a/Assets/Resources/Shaders/FSRTest.shader b/Assets/Resources/Shaders/FSRTest.shader deleted file mode 100644 index 3f4fdb7..0000000 --- a/Assets/Resources/Shaders/FSRTest.shader +++ /dev/null @@ -1,40 +0,0 @@ -Shader "FSR2/FSRTest" -{ - Properties - { - _MainTex ("Texture", 2D) = "" {} - } - SubShader { - - Pass { - ZTest Always Cull Off ZWrite Off - - HLSLPROGRAM - // include the unityCG.cginc - #include "UnityCG.cginc" - - // The default vert setup used in all the shaders - struct v2f { - float4 vertex : SV_POSITION; - float2 texCoord : TEXCOORD0; - }; - - #pragma vertex vert_img - #pragma fragment frag - - sampler2D _MainTex; - sampler2D _CameraDepthTexture; - sampler2D_half _CameraMotionVectorsTexture; - - fixed4 frag(v2f i) : COLOR - { - return tex2D(_MainTex, i.texCoord).rgba; - return fixed4(((tex2D(_CameraMotionVectorsTexture, i.texCoord) + 0.5f) / 2.0f).xyz, 1.0f); - //return tex2D(_CameraDepthTexture, i.texCoord).rrra; - } - ENDHLSL - - } - } - Fallback Off -} diff --git a/Assets/Resources/Shaders/FSRTest.shader.meta b/Assets/Resources/Shaders/FSRTest.shader.meta deleted file mode 100644 index fe134f1..0000000 --- a/Assets/Resources/Shaders/FSRTest.shader.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: ad642f5802989914585b30523ba86017 -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - preprocessorOverride: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Fsr2.cs b/Assets/Scripts/Fsr2.cs index 8297e29..15371a8 100644 --- a/Assets/Scripts/Fsr2.cs +++ b/Assets/Scripts/Fsr2.cs @@ -58,6 +58,11 @@ namespace FidelityFX renderWidth = (uint)(displayWidth / ratio); renderHeight = (uint)(displayHeight / ratio); } + + public static float GetMipmapBiasOffset(float renderScale) + { + return Mathf.Log(renderScale, 2.0f) - 1.0f; + } public static int GetJitterPhaseCount(int renderWidth, int displayWidth) { diff --git a/Assets/Scripts/Fsr2Controller.cs b/Assets/Scripts/Fsr2Controller.cs index a746ab6..d6ac813 100644 --- a/Assets/Scripts/Fsr2Controller.cs +++ b/Assets/Scripts/Fsr2Controller.cs @@ -47,7 +47,7 @@ public class Fsr2Controller : MonoBehaviour { if (_copyDepthMat == null) { - var copyDepthShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2CopyDepth"); + var copyDepthShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2_CopyDepth"); _copyDepthMat = new Material(copyDepthShader); } @@ -62,7 +62,7 @@ public class Fsr2Controller : MonoBehaviour { if (_copyMotionMat == null) { - var copyMotionShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2CopyMotionVectors"); + var copyMotionShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2_CopyMotionVectors"); _copyMotionMat = new Material(copyMotionShader); } @@ -88,6 +88,7 @@ public class Fsr2Controller : MonoBehaviour // TODO: enable motion vector jitter cancellation or not? _context = Fsr2.CreateContext(DisplaySize, RenderSize); + // TODO: do we need a depth buffer for the output? We will need depth & motion vectors for subsequent post-FX. How should FSR2 output these? _outputRT = new RenderTexture(DisplaySize.x, DisplaySize.y, 24, RenderTextureFormat.ARGBHalf) { enableRandomWrite = true }; _outputRT.Create(); @@ -122,11 +123,11 @@ public class Fsr2Controller : MonoBehaviour public void UpdateInputResources(RenderTexture src) { // I hate having to allocate extra RTs just to duplicate already existing Unity render buffers, but AFAIK there is no way to directly address these buffers individually from code - var renderSize = RenderSize; - _colorRT = RenderTexture.GetTemporary(renderSize.x, renderSize.y, 0, RenderTextureFormat.ARGBHalf); - _depthRT = RenderTexture.GetTemporary(renderSize.x, renderSize.y, 0, RenderTextureFormat.RFloat); - _motionVectorsRT = RenderTexture.GetTemporary(renderSize.x, renderSize.y, 0, RenderTextureFormat.RGHalf); + _colorRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGBHalf); + _depthRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.RFloat); + _motionVectorsRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.RGHalf); + // TODO: might be able to combine color + depth into a single RT and separate them out using RenderTextureSubElement Graphics.Blit(src, _colorRT); Graphics.Blit(src, _depthRT, CopyDepthMaterial); Graphics.Blit(src, _motionVectorsRT, CopyMotionVectorsMaterial); diff --git a/Assets/Scripts/SubsampleTest.cs b/Assets/Scripts/SubsampleTest.cs index d1e091c..5aee828 100644 --- a/Assets/Scripts/SubsampleTest.cs +++ b/Assets/Scripts/SubsampleTest.cs @@ -61,13 +61,13 @@ public class SubsampleTest : MonoBehaviour // Adjust texture mipmap LOD bias by log2(renderResolution/displayResolution) - 1.0; // May need to leave this to the game dev, as we don't know which textures do and don't belong to the 3D scene - float biasOffset = GetMipmapBiasOffset(); + float biasOffset = Fsr2.GetMipmapBiasOffset(renderScale); Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset); } private void OnDisable() { - float biasOffset = GetMipmapBiasOffset(); + float biasOffset = Fsr2.GetMipmapBiasOffset(renderScale); Fsr2.GlobalCallbacks.ApplyMipmapBias(-biasOffset); gameCamera.targetTexture.Release(); @@ -77,11 +77,6 @@ public class SubsampleTest : MonoBehaviour outputCamera.enabled = false; } - public float GetMipmapBiasOffset() - { - return Mathf.Log(renderScale) - 1.0f; - } - private void Update() { outputCamera.enabled = gameCamera.enabled;