From 9b15d2b84f652ab0ba336a1cd560a3f03157518b Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 13 Jun 2023 13:05:38 +0200 Subject: [PATCH] Reworked dynamic resolution to use ScalableBufferManager. Doesn't actually work correctly yet, but that'll be the next step. --- Assets/Scenes/SampleScenePPV2.unity | 2 +- Assets/Scripts/DebugDumper.cs | 15 ++++++++++++--- .../Runtime/Effects/SuperResolution.cs | 17 ++++++++--------- ProjectSettings/ProjectSettings.asset | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Assets/Scenes/SampleScenePPV2.unity b/Assets/Scenes/SampleScenePPV2.unity index 1da98f7..cac09d2 100644 --- a/Assets/Scenes/SampleScenePPV2.unity +++ b/Assets/Scenes/SampleScenePPV2.unity @@ -285,7 +285,7 @@ Camera: m_TargetEye: 3 m_HDR: 1 m_AllowMSAA: 0 - m_AllowDynamicResolution: 0 + m_AllowDynamicResolution: 1 m_ForceIntoRT: 0 m_OcclusionCulling: 1 m_StereoConvergence: 10 diff --git a/Assets/Scripts/DebugDumper.cs b/Assets/Scripts/DebugDumper.cs index e4d956e..eb7f1da 100644 --- a/Assets/Scripts/DebugDumper.cs +++ b/Assets/Scripts/DebugDumper.cs @@ -46,7 +46,16 @@ public class DebugDumper : MonoBehaviour Debug.Log(sb); _layer = GetComponent(); - _layer.superResolution.dynamicScale = _scaleFactor; + } + + void OnEnable() + { + ScalableBufferManager.ResizeBuffers(_scaleFactor, _scaleFactor); + } + + void OnDisable() + { + ScalableBufferManager.ResizeBuffers(1f, 1f); } void Update() @@ -90,7 +99,7 @@ public class DebugDumper : MonoBehaviour _scaleFactor += 0.05f * Math.Sign(vertical); _scaleFactor = Mathf.Clamp(_scaleFactor, 0.1f, 1.0f); - _layer.superResolution.dynamicScale = _scaleFactor; + ScalableBufferManager.ResizeBuffers(_scaleFactor, _scaleFactor); _lastScaleTime = Time.realtimeSinceStartup; } } @@ -109,7 +118,7 @@ public class DebugDumper : MonoBehaviour GUILayout.Label($"FSR2: {(_layer.antialiasingMode == PostProcessLayer.Antialiasing.SuperResolution ? "Enabled" : "Disabled")}"); GUILayout.Label($"Quality: {_layer.superResolution.qualityMode}"); GUILayout.Label($"Auto-exposure: {(_layer.superResolution.exposureSource)}"); - GUILayout.Label($"Scale: {_layer.superResolution.dynamicScale:0.00}"); + GUILayout.Label($"Scale: {_scaleFactor:0.00}"); if (Input.GetButton("Jump")) { GUILayout.Label("Reset"); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs index fb3f6ac..3a2c250 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs @@ -99,9 +99,8 @@ namespace UnityEngine.Rendering.PostProcessing [Range(0, 1)] public float autoReactiveMax = 0.9f; } - public float dynamicScale { get; set; } = 1.0f; public Vector2 jitter { get; private set; } - public Vector2Int renderSize => GetScaledRenderSize(); + public Vector2Int renderSize => _maxRenderSize; public Vector2Int displaySize => _displaySize; public RenderTargetIdentifier colorOpaqueOnly { get; set; } @@ -158,7 +157,7 @@ namespace UnityEngine.Rendering.PostProcessing _maxRenderSize = new Vector2Int(maxRenderWidth, maxRenderHeight); // Render to a smaller portion of the screen by manipulating the camera's viewport rect - var scaledRenderSize = GetScaledRenderSize(); + var scaledRenderSize = GetScaledRenderSize(context.camera); camera.aspect = (_displaySize.x * _originalRect.width) / (_displaySize.y * _originalRect.height); camera.rect = new Rect(0, 0, _originalRect.width * scaledRenderSize.x / _displaySize.x, _originalRect.height * scaledRenderSize.y / _displaySize.y); } @@ -250,7 +249,7 @@ namespace UnityEngine.Rendering.PostProcessing private void ApplyJitter(Camera camera) { - var scaledRenderSize = GetScaledRenderSize(); + var scaledRenderSize = GetScaledRenderSize(camera); // Perform custom jittering of the camera's projection matrix according to FSR2's recipe int jitterPhaseCount = Fsr2.GetJitterPhaseCount(scaledRenderSize.x, _displaySize.x); @@ -287,7 +286,7 @@ namespace UnityEngine.Rendering.PostProcessing if (reactiveMask != null) _dispatchDescription.Reactive = reactiveMask; if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask; - var scaledRenderSize = GetScaledRenderSize(); + var scaledRenderSize = GetScaledRenderSize(context.camera); _dispatchDescription.Output = context.destination; _dispatchDescription.PreExposure = preExposure; @@ -328,19 +327,19 @@ namespace UnityEngine.Rendering.PostProcessing _genReactiveDescription.ColorOpaqueOnly = colorOpaqueOnly; _genReactiveDescription.ColorPreUpscale = null; _genReactiveDescription.OutReactive = null; - _genReactiveDescription.RenderSize = GetScaledRenderSize(); + _genReactiveDescription.RenderSize = GetScaledRenderSize(context.camera); _genReactiveDescription.Scale = generateReactiveParameters.scale; _genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold; _genReactiveDescription.BinaryValue = generateReactiveParameters.binaryValue; _genReactiveDescription.Flags = generateReactiveParameters.flags; } - private Vector2Int GetScaledRenderSize() + private Vector2Int GetScaledRenderSize(Camera camera) { - if (Mathf.Approximately(dynamicScale, 1.0f)) + if (!RuntimeUtilities.IsDynamicResolutionEnabled(camera)) return _maxRenderSize; - return new Vector2Int(Mathf.CeilToInt(_maxRenderSize.x * dynamicScale), Mathf.CeilToInt(_maxRenderSize.y * dynamicScale)); + return new Vector2Int(Mathf.CeilToInt(_maxRenderSize.x * ScalableBufferManager.widthScaleFactor), Mathf.CeilToInt(_maxRenderSize.y * ScalableBufferManager.heightScaleFactor)); } private class Callbacks : Fsr2CallbacksBase diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 9279905..1e53714 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -144,7 +144,7 @@ PlayerSettings: vrSettings: enable360StereoCapture: 0 isWsaHolographicRemotingEnabled: 0 - enableFrameTimingStats: 0 + enableFrameTimingStats: 1 enableOpenGLProfilerGPURecorders: 1 useHDRDisplay: 0 D3DHDRBitDepth: 0