From f184be7b6229002f06a6359ac8f38d17b392c2aa Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 26 Feb 2023 18:15:20 +0100 Subject: [PATCH] Some minor optimizations and cleanup --- Assets/Scripts/Fsr2Controller.cs | 12 ++++++++---- Assets/Scripts/SubsampleTest.cs | 17 +++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/Fsr2Controller.cs b/Assets/Scripts/Fsr2Controller.cs index 83761dd..e80188f 100644 --- a/Assets/Scripts/Fsr2Controller.cs +++ b/Assets/Scripts/Fsr2Controller.cs @@ -68,11 +68,11 @@ public class Fsr2Controller : MonoBehaviour if (!_started) return; - _context = Fsr2.CreateContext(DisplaySize, RenderSize, Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation | Fsr2.InitializationFlags.EnableFP16Usage); + _context = Fsr2.CreateContext(DisplaySize, RenderSize, Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation); // 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? // TODO: can probably be a temporary RT - _upscaledOutput = new RenderTexture(DisplaySize.x, DisplaySize.y, 24, RenderTextureFormat.ARGBHalf) { name = "FSR2 Upscaled Output", enableRandomWrite = true }; + _upscaledOutput = new RenderTexture(DisplaySize.x, DisplaySize.y, 0, RenderTextureFormat.ARGBHalf) { name = "FSR2 Upscaled Output", enableRandomWrite = true }; _upscaledOutput.Create(); } @@ -105,6 +105,9 @@ public class Fsr2Controller : MonoBehaviour var motionVectors = RenderTexture.GetTemporary(renderBuffer.width, renderBuffer.height, 0, RenderTextureFormat.RGHalf); Graphics.Blit(renderBuffer, motionVectors, CopyMotionVectorsMaterial); + // TODO: if `dest` is null, we are rendering straight to the backbuffer and should use a temporary RT as the output buffer for FSR2 + // TODO: if `dest` it NOT null, we have more image effects lined up after this one, and we should be able to have FSR2 output straight to `dest` without an intermediary temp RT + _dispatchDescription.ColorDepth = renderBuffer; _dispatchDescription.MotionVectors = motionVectors; _dispatchDescription.Output = _upscaledOutput; @@ -126,10 +129,11 @@ public class Fsr2Controller : MonoBehaviour _context.Dispatch(_dispatchDescription); - RenderTexture.ReleaseTemporary(motionVectors); - // Output upscaled image to screen // TODO: we should probably use a shader to include depth & motion vectors into the output + // TODO: if `dest` is null, we likely don't care about the depth & motion vectors anymore Graphics.Blit(_upscaledOutput, dest); + + RenderTexture.ReleaseTemporary(motionVectors); } } diff --git a/Assets/Scripts/SubsampleTest.cs b/Assets/Scripts/SubsampleTest.cs index 21fedfb..888aceb 100644 --- a/Assets/Scripts/SubsampleTest.cs +++ b/Assets/Scripts/SubsampleTest.cs @@ -38,11 +38,15 @@ public class SubsampleTest : MonoBehaviour //outputCameraObject.transform.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; outputCamera = outputCameraObject.AddComponent(); - //outputCamera.CopyFrom(gameCamera); + outputCamera.backgroundColor = Color.clear; + outputCamera.clearFlags = CameraClearFlags.Nothing; outputCamera.eventMask = 0; outputCamera.cullingMask = 0; - outputCamera.clearFlags = CameraClearFlags.Nothing; - + outputCamera.useOcclusionCulling = false; + outputCamera.orthographic = true; + outputCamera.allowMSAA = false; + outputCamera.renderingPath = RenderingPath.Forward; + _fsr2Controller = outputCameraObject.AddComponent(); } @@ -58,9 +62,9 @@ public class SubsampleTest : MonoBehaviour 24, // Can we copy depth value from original camera? RenderTextureFormat.ARGBHalf); // Can we copy format from original camera? Or renderer quality settings? - gameCamera.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.DepthNormals | DepthTextureMode.MotionVectors; + gameCamera.depthTextureMode |= DepthTextureMode.Depth | DepthTextureMode.MotionVectors; - gameCamera.targetTexture.name = "FSR2 Source Texture"; + gameCamera.targetTexture.name = "FSR2 Input Texture"; gameCamera.targetTexture.Create(); // Adjust texture mipmap LOD bias by log2(renderResolution/displayResolution) - 1.0; @@ -94,9 +98,6 @@ public class SubsampleTest : MonoBehaviour } outputCamera.enabled = gameCamera.enabled; - //outputCamera.CopyFrom(gameCamera); - - outputCamera.clearFlags = CameraClearFlags.Color; if (Screen.width != _prevScreenSize.x || Screen.height != _prevScreenSize.y || qualityMode != _prevQualityMode) {