Browse Source

Made a start on showing FSR2 parameters in the inspector

stable
Nico de Poel 3 years ago
parent
commit
4982b959d5
  1. 23
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs
  2. 88
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs

23
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs

@ -30,6 +30,13 @@ namespace UnityEditor.Rendering.PostProcessing
SerializedProperty m_FxaaFastMode;
SerializedProperty m_FxaaKeepAlpha;
SerializedProperty m_FsrQualityMode;
SerializedProperty m_FsrPerformSharpen;
SerializedProperty m_FsrSharpness;
SerializedProperty m_FsrAutoExposure;
SerializedProperty m_FsrAutoReactive;
SerializedProperty m_FsrAutoReactiveParams;
SerializedProperty m_FogEnabled;
SerializedProperty m_FogExcludeSkybox;
@ -75,6 +82,13 @@ namespace UnityEditor.Rendering.PostProcessing
m_FxaaFastMode = FindProperty(x => x.fastApproximateAntialiasing.fastMode);
m_FxaaKeepAlpha = FindProperty(x => x.fastApproximateAntialiasing.keepAlpha);
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_FsrAutoReactive = FindProperty(x => x.superResolution.autoGenerateReactiveMask);
m_FsrAutoReactiveParams = FindProperty(x => x.superResolution.generateReactiveParameters);
m_FogEnabled = FindProperty(x => x.fog.enabled);
m_FogExcludeSkybox = FindProperty(x => x.fog.excludeSkybox);
@ -194,6 +208,15 @@ namespace UnityEditor.Rendering.PostProcessing
if (!m_FxaaFastMode.boolValue && EditorUtilities.isTargetingConsolesOrMobiles)
EditorGUILayout.HelpBox("For performance reasons it is recommended to use Fast Mode on mobile and console platforms.", MessageType.Warning);
}
else if (m_AntialiasingMode.intValue == (int)PostProcessLayer.Antialiasing.SuperResolution)
{
EditorGUILayout.PropertyField(m_FsrQualityMode);
EditorGUILayout.PropertyField(m_FsrPerformSharpen);
EditorGUILayout.PropertyField(m_FsrSharpness);
EditorGUILayout.PropertyField(m_FsrAutoExposure);
EditorGUILayout.PropertyField(m_FsrAutoReactive);
if (m_FsrAutoReactive.boolValue) EditorGUILayout.PropertyField(m_FsrAutoReactiveParams);
}
}
EditorGUI.indentLevel--;

88
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs

@ -28,47 +28,47 @@ using FidelityFX;
namespace UnityEngine.Rendering.PostProcessing
{
[Serializable]
public class Fsr2QualityModeParameter : ParameterOverride<Fsr2.QualityMode>
{
}
[Serializable]
public class Fsr2GenerateReactiveParameters: ParameterOverride<Fsr2GenerateReactiveParams>
{
}
[Serializable]
public class Fsr2GenerateReactiveParams
{
[Range(0, 2)] public float scale = 0.5f;
[Range(0, 1)] public float cutoffThreshold = 0.2f;
[Range(0, 1)] public float binaryValue = 0.9f;
public Fsr2.GenerateReactiveFlags flags = Fsr2.GenerateReactiveFlags.ApplyTonemap | Fsr2.GenerateReactiveFlags.ApplyThreshold | Fsr2.GenerateReactiveFlags.UseComponentsMax;
}
[UnityEngine.Scripting.Preserve]
[Serializable]
public class SuperResolution
{
public Fsr2QualityModeParameter qualityMode = new Fsr2QualityModeParameter() { value = Fsr2.QualityMode.Quality };
public static Func<PostProcessRenderContext, IFsr2Callbacks> CallbacksFactory { get; set; } = (context) => new Callbacks(context.resources);
[Tooltip("Standard scaling ratio presets.")]
public Fsr2.QualityMode qualityMode = Fsr2.QualityMode.Quality;
public BoolParameter performSharpenPass = new BoolParameter() { value = true };
[Range(0, 1)] public FloatParameter sharpness = new FloatParameter() { value = 0.8f };
[Tooltip("Apply RCAS sharpening to the image after upscaling.")]
public bool performSharpenPass = true;
[Tooltip("Strength of the sharpening effect.")]
[Range(0, 1)] public float sharpness = 0.8f;
[Tooltip("Allow the use of half precision compute operations, potentially improving performance")]
public BoolParameter enableFP16 = new BoolParameter() { value = false };
[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("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;
[Header("Exposure")]
public BoolParameter enableAutoExposure = new BoolParameter() { value = true };
public FloatParameter preExposure = new FloatParameter() { value = 1.0f };
public TextureParameter exposure = new TextureParameter() { value = null };
[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.")]
public Texture transparencyAndCompositionMask = null;
[Tooltip("Automatically generate a reactive mask based on the difference between opaque-only render output and the final render output including alpha transparencies.")]
public bool autoGenerateReactiveMask = true;
[Tooltip("Parameters to control the process of auto-generating a reactive mask.")]
public GenerateReactiveParameters generateReactiveParameters = new GenerateReactiveParameters();
[Header("Reactivity, Transparency & Composition")]
public TextureParameter reactiveMask = new TextureParameter() { value = null };
public TextureParameter transparencyAndCompositionMask = new TextureParameter() { value = null };
public BoolParameter autoGenerateReactiveMask = new BoolParameter() { value = true };
public Fsr2GenerateReactiveParameters generateReactiveParameters = new Fsr2GenerateReactiveParameters();
[Serializable]
public class GenerateReactiveParameters
{
[Range(0, 2)] public float scale = 0.5f;
[Range(0, 1)] public float cutoffThreshold = 0.2f;
[Range(0, 1)] public float binaryValue = 0.9f;
public Fsr2.GenerateReactiveFlags flags = Fsr2.GenerateReactiveFlags.ApplyTonemap | Fsr2.GenerateReactiveFlags.ApplyThreshold | Fsr2.GenerateReactiveFlags.UseComponentsMax;
}
public Vector2 jitter { get; private set; }
@ -106,13 +106,7 @@ namespace UnityEngine.Rendering.PostProcessing
public void Render(PostProcessRenderContext context)
{
var cmd = context.command;
if (!Application.isPlaying)
{
// We don't want this effect to start injecting scripts in edit mode, so just blit and skip the rest entirely
cmd.BlitFullscreenTriangle(context.source, context.destination);
return;
}
cmd.BeginSample("FSR2");
// 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
@ -143,6 +137,9 @@ namespace UnityEngine.Rendering.PostProcessing
cmd.BlitFullscreenTriangle(Fsr2ShaderIDs.UavUpscaledOutput, context.destination);
cmd.ReleaseTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput);
cmd.EndSample("FSR2");
_reset = false;
}
private void CreateFsrContext(PostProcessRenderContext context)
@ -161,7 +158,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage;
if (enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure;
_fsrContext = Fsr2.CreateContext(_displaySize, _renderSize, new Callbacks(context.resources), flags);
_fsrContext = Fsr2.CreateContext(_displaySize, _renderSize, CallbacksFactory(context), flags);
// Apply a mipmap bias so that textures retain their sharpness
float biasOffset = Fsr2.GetMipmapBiasOffset(_renderSize.x, _displaySize.x);
@ -213,9 +210,9 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription.Reactive = null;
_dispatchDescription.TransparencyAndComposition = null;
if (!enableAutoExposure && exposure.value != null) _dispatchDescription.Exposure = exposure.value;
if (reactiveMask.value != null) _dispatchDescription.Reactive = reactiveMask.value;
if (transparencyAndCompositionMask.value != null) _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask.value;
if (!enableAutoExposure && exposure != null) _dispatchDescription.Exposure = exposure;
if (reactiveMask != null) _dispatchDescription.Reactive = reactiveMask;
if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask;
_dispatchDescription.Output = null;
_dispatchDescription.PreExposure = preExposure;
@ -230,8 +227,7 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription.CameraFovAngleVertical = camera.fieldOfView * Mathf.Deg2Rad;
_dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity
_dispatchDescription.Reset = _reset;
_reset = false;
if (SystemInfo.usesReversedZBuffer)
{
// Swap the near and far clip plane distances as FSR2 expects this when using inverted depth

Loading…
Cancel
Save