From 23d26aa84bc34c1ceb77ab2d2dbf10741088237d Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 30 May 2023 18:40:36 +0200 Subject: [PATCH] Allow a choice for exposure value source: either auto-calculated from FSR2 or Unity, or a manual texture, or the default value. --- Assets/Scenes/SampleScenePPV2.unity | 2 +- .../Editor/PostProcessLayerEditor.cs | 7 ++--- .../Runtime/Effects/SuperResolution.cs | 26 +++++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Assets/Scenes/SampleScenePPV2.unity b/Assets/Scenes/SampleScenePPV2.unity index 2adfc86..3cfd5da 100644 --- a/Assets/Scenes/SampleScenePPV2.unity +++ b/Assets/Scenes/SampleScenePPV2.unity @@ -350,7 +350,7 @@ MonoBehaviour: performSharpenPass: 1 sharpness: 0.8 enableFP16: 0 - enableAutoExposure: 1 + exposureSource: 1 preExposure: 1 exposure: {fileID: 0} reactiveMask: {fileID: 0} diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs index 975ac4f..1d98030 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs @@ -33,7 +33,7 @@ namespace UnityEditor.Rendering.PostProcessing SerializedProperty m_FsrQualityMode; SerializedProperty m_FsrPerformSharpen; SerializedProperty m_FsrSharpness; - SerializedProperty m_FsrAutoExposure; + SerializedProperty m_FsrExposureSource; SerializedProperty m_FsrAutoReactive; SerializedProperty m_FsrAutoReactiveParams; SerializedProperty m_FsrAutoTcr; @@ -87,7 +87,7 @@ namespace UnityEditor.Rendering.PostProcessing m_FsrQualityMode = FindProperty(x => x.superResolution.qualityMode); m_FsrPerformSharpen = FindProperty(x => x.superResolution.performSharpenPass); m_FsrSharpness = FindProperty(x => x.superResolution.sharpness); - m_FsrAutoExposure = FindProperty(x => x.superResolution.enableAutoExposure); + m_FsrExposureSource = FindProperty(x => x.superResolution.exposureSource); m_FsrAutoReactive = FindProperty(x => x.superResolution.autoGenerateReactiveMask); m_FsrAutoReactiveParams = FindProperty(x => x.superResolution.generateReactiveParameters); m_FsrAutoTcr = FindProperty(x => x.superResolution.autoGenerateTransparencyAndComposition); @@ -214,10 +214,11 @@ namespace UnityEditor.Rendering.PostProcessing } else if (m_AntialiasingMode.intValue == (int)PostProcessLayer.Antialiasing.SuperResolution) { + // TODO: add remaining FSR2 options EditorGUILayout.PropertyField(m_FsrQualityMode); EditorGUILayout.PropertyField(m_FsrPerformSharpen); EditorGUILayout.PropertyField(m_FsrSharpness); - EditorGUILayout.PropertyField(m_FsrAutoExposure); + EditorGUILayout.PropertyField(m_FsrExposureSource); EditorGUILayout.PropertyField(m_FsrAutoReactive); if (m_FsrAutoReactive.boolValue) EditorGUILayout.PropertyField(m_FsrAutoReactiveParams); EditorGUILayout.PropertyField(m_FsrAutoTcr); 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 12f59c6..0aa4e35 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 @@ -44,13 +44,21 @@ namespace UnityEngine.Rendering.PostProcessing [Tooltip("Allow the use of half precision compute operations, potentially improving performance if the platform supports it.")] public bool enableFP16 = false; - [Tooltip("Allow an exposure value to be computed internally. When set to false, either the provided exposure texture or a default exposure value will be used.")] - public bool enableAutoExposure = true; + [Tooltip("Choose where to get the exposure value from. Use auto-exposure from either FSR2 or Unity, provide a manual exposure texture, or use a default value.")] + public ExposureSource exposureSource = ExposureSource.Auto; [Tooltip("Value by which the input signal will be divided, to get back to the original signal produced by the game.")] public float preExposure = 1.0f; [Tooltip("Optional 1x1 texture containing the exposure value for the current frame.")] public Texture exposure = null; + public enum ExposureSource + { + Default, + Auto, + Unity, + Manual, + } + [Tooltip("Optional texture to control the influence of the current frame on the reconstructed output. If unset, either an auto-generated or a default cleared reactive mask will be used.")] public Texture reactiveMask = null; [Tooltip("Optional texture for marking areas of specialist rendering which should be accounted for during the upscaling process. If unset, a default cleared mask will be used.")] @@ -107,6 +115,7 @@ namespace UnityEngine.Rendering.PostProcessing private readonly Fsr2.GenerateReactiveDescription _genReactiveDescription = new Fsr2.GenerateReactiveDescription(); private Fsr2.QualityMode _prevQualityMode; + private ExposureSource _prevExposureSource; private Vector2Int _prevDisplaySize; private Rect _originalRect; @@ -161,12 +170,10 @@ namespace UnityEngine.Rendering.PostProcessing // Monitor for any resolution changes and recreate the FSR2 context if necessary // We can't create an FSR2 context without info from the post-processing context, so delay the initial setup until here - if (_fsrContext == null || _displaySize.x != _prevDisplaySize.x || _displaySize.y != _prevDisplaySize.y || qualityMode != _prevQualityMode) + if (_fsrContext == null || _displaySize.x != _prevDisplaySize.x || _displaySize.y != _prevDisplaySize.y || qualityMode != _prevQualityMode || exposureSource != _prevExposureSource) { DestroyFsrContext(); CreateFsrContext(context); - - _prevQualityMode = qualityMode; } cmd.SetGlobalTexture(Fsr2ShaderIDs.SrvInputColor, context.source); @@ -197,12 +204,14 @@ namespace UnityEngine.Rendering.PostProcessing private void CreateFsrContext(PostProcessRenderContext context) { + _prevQualityMode = qualityMode; + _prevExposureSource = exposureSource; _prevDisplaySize = _displaySize; Fsr2.InitializationFlags flags = 0; if (context.camera.allowHDR) flags |= Fsr2.InitializationFlags.EnableHighDynamicRange; if (enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage; - if (enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure; + if (exposureSource == ExposureSource.Auto) flags |= Fsr2.InitializationFlags.EnableAutoExposure; _callbacks = CallbacksFactory(context); _fsrContext = Fsr2.CreateContext(_displaySize, _renderSize, _callbacks, flags); @@ -262,8 +271,9 @@ namespace UnityEngine.Rendering.PostProcessing _dispatchDescription.Exposure = null; _dispatchDescription.Reactive = null; _dispatchDescription.TransparencyAndComposition = null; - - if (!enableAutoExposure && exposure != null) _dispatchDescription.Exposure = exposure; + + if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = exposure; + if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = context.autoExposureTexture; if (reactiveMask != null) _dispatchDescription.Reactive = reactiveMask; if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask;