diff --git a/Assets/Scripts/Fsr2Context.cs b/Assets/Scripts/Fsr2Context.cs index 771052d..3310b55 100644 --- a/Assets/Scripts/Fsr2Context.cs +++ b/Assets/Scripts/Fsr2Context.cs @@ -98,7 +98,7 @@ namespace FidelityFX _defaultExposureResource.SetPixel(0, 0, Color.black); _defaultExposureResource.Apply(); - // Resource FSR2_DefaultReactiviyMask: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE + // Resource FSR2_DefaultReactivityMask: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE _defaultReactiveResource = new Texture2D(1, 1, GraphicsFormat.R8_UNorm, TextureCreationFlags.None) { name = "FSR2_DefaultReactivityMask" }; _defaultReactiveResource.SetPixel(0, 0, Color.black); _defaultReactiveResource.Apply(); diff --git a/Assets/Scripts/Fsr2Controller.cs b/Assets/Scripts/Fsr2Controller.cs index 3655d67..a50c1d5 100644 --- a/Assets/Scripts/Fsr2Controller.cs +++ b/Assets/Scripts/Fsr2Controller.cs @@ -110,17 +110,23 @@ public class Fsr2Controller : MonoBehaviour RenderPipelineManager.endContextRendering -= OnEndContextRendering; } - public void UpdateInputResources(RenderTexture src) + public void OnRenderGameCamera(RenderTexture renderTarget, Vector2 jitterOffset) { // 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 - _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); + _colorRT = RenderTexture.GetTemporary(renderTarget.width, renderTarget.height, 0, RenderTextureFormat.ARGBHalf); + _depthRT = RenderTexture.GetTemporary(renderTarget.width, renderTarget.height, 0, RenderTextureFormat.RFloat); + _motionVectorsRT = RenderTexture.GetTemporary(renderTarget.width, renderTarget.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); + // TODO: we can copy to all RTs at the same time using a multi-target blit, requiring only a single shader + material + Graphics.Blit(renderTarget, _colorRT); + Graphics.Blit(renderTarget, _depthRT, CopyDepthMaterial); + Graphics.Blit(renderTarget, _motionVectorsRT, CopyMotionVectorsMaterial); + + _dispatchDescription.Color = _colorRT; + _dispatchDescription.Depth = _depthRT; + _dispatchDescription.MotionVectors = _motionVectorsRT; + _dispatchDescription.JitterOffset = jitterOffset; } // For scriptable rendering pipeline @@ -136,9 +142,6 @@ public class Fsr2Controller : MonoBehaviour if (_colorRT == null || _depthRT == null || _motionVectorsRT == null) return; - _dispatchDescription.Color = _colorRT; - _dispatchDescription.Depth = _depthRT; - _dispatchDescription.MotionVectors = _motionVectorsRT; _dispatchDescription.Output = _outputRT; _dispatchDescription.Exposure = null; _dispatchDescription.Reactive = null; diff --git a/Assets/Scripts/SubsampleTest.cs b/Assets/Scripts/SubsampleTest.cs index 5aee828..7016f33 100644 --- a/Assets/Scripts/SubsampleTest.cs +++ b/Assets/Scripts/SubsampleTest.cs @@ -19,6 +19,7 @@ public class SubsampleTest : MonoBehaviour private bool enableJitter; private Fsr2Controller _fsr2Controller; + private Vector2 _jitterOffset; private void OnEnable() { @@ -99,10 +100,10 @@ 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 = Fsr2.GetJitterPhaseCount(gameCamera.targetTexture.width, Screen.width); - Fsr2.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount); + Fsr2.GetJitterOffset(out _jitterOffset.x, out _jitterOffset.y, Time.frameCount, jitterPhaseCount); - jitterX = 2.0f * jitterX / gameCamera.targetTexture.width; - jitterY = -2.0f * jitterY / gameCamera.targetTexture.height; + float jitterX = 2.0f * _jitterOffset.x / gameCamera.targetTexture.width; + float jitterY = -2.0f * _jitterOffset.y / gameCamera.targetTexture.height; var jitterTranslationMatrix = Matrix4x4.Translate(new Vector3(jitterX, jitterY, 0)); gameCamera.projectionMatrix = jitterTranslationMatrix * gameCamera.nonJitteredProjectionMatrix; @@ -112,7 +113,7 @@ public class SubsampleTest : MonoBehaviour private void OnRenderImage(RenderTexture src, RenderTexture dest) { // We don't actually output any image from this camera; instead we pass its render buffers on to the FSR2 system - _fsr2Controller.UpdateInputResources(src); + _fsr2Controller.OnRenderGameCamera(src, _jitterOffset); // Shut up Unity warning about not writing anything to the destination texture Graphics.SetRenderTarget(dest);