Compare commits

...

13 Commits

  1. 28
      Assets/Scripts/DebugDumper.cs
  2. 31
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs
  3. 1
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset
  4. 16
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs
  5. 2
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR2Upscaler.cs
  6. 3
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3Upscaler.cs
  7. 193
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Upscaler.cs
  8. 37
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs
  9. 6
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs
  10. 2
      Packages/com.unity.postprocessing@3.2.2/package.json
  11. 2
      Packages/fidelityfx.fsr
  12. 2
      Packages/packages-lock.json

28
Assets/Scripts/DebugDumper.cs

@ -76,40 +76,40 @@ public class DebugDumper : MonoBehaviour
if (_layer.antialiasingMode == PostProcessLayer.Antialiasing.None) if (_layer.antialiasingMode == PostProcessLayer.Antialiasing.None)
{ {
_layer.antialiasingMode = PostProcessLayer.Antialiasing.AdvancedUpscaling; _layer.antialiasingMode = PostProcessLayer.Antialiasing.AdvancedUpscaling;
_layer.upscaling.upscalerType = default;
_layer.superResolution.upscalerType = default;
} }
else else
{ {
int newUpscalerType = (int)_layer.upscaling.upscalerType + 1;
int newUpscalerType = (int)_layer.superResolution.upscalerType + 1;
if (newUpscalerType >= Enum.GetValues(typeof(Upscaling.UpscalerType)).Length) if (newUpscalerType >= Enum.GetValues(typeof(Upscaling.UpscalerType)).Length)
{ {
_layer.antialiasingMode = PostProcessLayer.Antialiasing.None; _layer.antialiasingMode = PostProcessLayer.Antialiasing.None;
_layer.upscaling.upscalerType = default;
_layer.superResolution.upscalerType = default;
} }
else else
{ {
_layer.antialiasingMode = PostProcessLayer.Antialiasing.AdvancedUpscaling; _layer.antialiasingMode = PostProcessLayer.Antialiasing.AdvancedUpscaling;
_layer.upscaling.upscalerType = (Upscaling.UpscalerType)newUpscalerType;
_layer.superResolution.upscalerType = (Upscaling.UpscalerType)newUpscalerType;
} }
} }
} }
if (Input.GetButtonDown("Fire2")) if (Input.GetButtonDown("Fire2"))
{ {
int quality = (int)_layer.upscaling.qualityMode;
int quality = (int)_layer.superResolution.qualityMode;
quality = (quality + 1) % Enum.GetValues(typeof(Fsr2.QualityMode)).Length; quality = (quality + 1) % Enum.GetValues(typeof(Fsr2.QualityMode)).Length;
_layer.upscaling.qualityMode = (Fsr2.QualityMode)quality;
_layer.superResolution.qualityMode = (Fsr2.QualityMode)quality;
} }
if (Input.GetButtonDown("Fire3")) if (Input.GetButtonDown("Fire3"))
{ {
_layer.upscaling.exposureSource =
_layer.upscaling.exposureSource != Upscaling.ExposureSource.Auto ? Upscaling.ExposureSource.Auto : Upscaling.ExposureSource.Default;
_layer.superResolution.exposureSource =
_layer.superResolution.exposureSource != Upscaling.ExposureSource.Auto ? Upscaling.ExposureSource.Auto : Upscaling.ExposureSource.Default;
} }
if (Input.GetButtonDown("Jump")) if (Input.GetButtonDown("Jump"))
{ {
_layer.upscaling.ResetHistory();
_layer.superResolution.ResetHistory();
} }
float vertical = Input.GetAxis("Vertical"); float vertical = Input.GetAxis("Vertical");
@ -134,13 +134,13 @@ public class DebugDumper : MonoBehaviour
GUI.matrix = Matrix4x4.Scale(new Vector3(scale, scale, scale)); GUI.matrix = Matrix4x4.Scale(new Vector3(scale, scale, scale));
} }
var renderSize = _layer.upscaling.MaxRenderSize;
var displaySize = _layer.upscaling.UpscaleSize;
var renderSize = _layer.superResolution.MaxRenderSize;
var displaySize = _layer.superResolution.UpscaleSize;
GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
GUILayout.Label($"Upscaler: {(_layer.antialiasingMode == PostProcessLayer.Antialiasing.AdvancedUpscaling ? _layer.upscaling.upscalerType.ToString() : "None")}");
GUILayout.Label($"Quality: {_layer.upscaling.qualityMode}");
GUILayout.Label($"Exposure: {(_layer.upscaling.exposureSource)}");
GUILayout.Label($"Upscaler: {(_layer.antialiasingMode == PostProcessLayer.Antialiasing.AdvancedUpscaling ? _layer.superResolution.upscalerType.ToString() : "None")}");
GUILayout.Label($"Quality: {_layer.superResolution.qualityMode}");
GUILayout.Label($"Exposure: {(_layer.superResolution.exposureSource)}");
GUILayout.Label($"Scale: {Mathf.RoundToInt(_scaleFactor * 100)}%"); GUILayout.Label($"Scale: {Mathf.RoundToInt(_scaleFactor * 100)}%");
GUILayout.Label($"Render: {Mathf.CeilToInt(renderSize.x * _scaleFactor)}x{Mathf.CeilToInt(renderSize.y * _scaleFactor)}"); GUILayout.Label($"Render: {Mathf.CeilToInt(renderSize.x * _scaleFactor)}x{Mathf.CeilToInt(renderSize.y * _scaleFactor)}");
GUILayout.Label($"Display: {displaySize.x}x{displaySize.y}"); GUILayout.Label($"Display: {displaySize.x}x{displaySize.y}");

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

@ -34,6 +34,7 @@ namespace UnityEditor.Rendering.PostProcessing
SerializedProperty m_FsrQualityMode; SerializedProperty m_FsrQualityMode;
SerializedProperty m_FsrPerformSharpen; SerializedProperty m_FsrPerformSharpen;
SerializedProperty m_FsrSharpness; SerializedProperty m_FsrSharpness;
SerializedProperty m_FsrVelocityFactor;
SerializedProperty m_FsrExposureSource; SerializedProperty m_FsrExposureSource;
SerializedProperty m_FsrExposureTexture; SerializedProperty m_FsrExposureTexture;
SerializedProperty m_FsrPreExposure; SerializedProperty m_FsrPreExposure;
@ -90,20 +91,21 @@ namespace UnityEditor.Rendering.PostProcessing
m_FxaaFastMode = FindProperty(x => x.fastApproximateAntialiasing.fastMode); m_FxaaFastMode = FindProperty(x => x.fastApproximateAntialiasing.fastMode);
m_FxaaKeepAlpha = FindProperty(x => x.fastApproximateAntialiasing.keepAlpha); m_FxaaKeepAlpha = FindProperty(x => x.fastApproximateAntialiasing.keepAlpha);
m_UpscalerType = FindProperty(x => x.upscaling.upscalerType);
m_FsrQualityMode = FindProperty(x => x.upscaling.qualityMode);
m_FsrPerformSharpen = FindProperty(x => x.upscaling.performSharpenPass);
m_FsrSharpness = FindProperty(x => x.upscaling.sharpness);
m_FsrExposureSource = FindProperty(x => x.upscaling.exposureSource);
m_FsrExposureTexture = FindProperty(x => x.upscaling.exposure);
m_FsrPreExposure = FindProperty(x => x.upscaling.preExposure);
m_FsrDebugView = FindProperty(x => x.upscaling.enableDebugView);
m_FsrAutoReactive = FindProperty(x => x.upscaling.autoGenerateReactiveMask);
m_FsrAutoReactiveParams = FindProperty(x => x.upscaling.generateReactiveParameters);
m_FsrReactiveMaskTexture = FindProperty(x => x.upscaling.reactiveMask);
m_FsrAutoTcr = FindProperty(x => x.upscaling.autoGenerateTransparencyAndComposition);
m_FsrAutoTcrParams = FindProperty(x => x.upscaling.generateTransparencyAndCompositionParameters);
m_FsrTcrMaskTexture = FindProperty(x => x.upscaling.transparencyAndCompositionMask);
m_UpscalerType = FindProperty(x => x.superResolution.upscalerType);
m_FsrQualityMode = FindProperty(x => x.superResolution.qualityMode);
m_FsrPerformSharpen = FindProperty(x => x.superResolution.performSharpenPass);
m_FsrSharpness = FindProperty(x => x.superResolution.sharpness);
m_FsrVelocityFactor = FindProperty(x => x.superResolution.velocityFactor);
m_FsrExposureSource = FindProperty(x => x.superResolution.exposureSource);
m_FsrExposureTexture = FindProperty(x => x.superResolution.exposure);
m_FsrPreExposure = FindProperty(x => x.superResolution.preExposure);
m_FsrDebugView = FindProperty(x => x.superResolution.enableDebugView);
m_FsrAutoReactive = FindProperty(x => x.superResolution.autoGenerateReactiveMask);
m_FsrAutoReactiveParams = FindProperty(x => x.superResolution.generateReactiveParameters);
m_FsrReactiveMaskTexture = FindProperty(x => x.superResolution.reactiveMask);
m_FsrAutoTcr = FindProperty(x => x.superResolution.autoGenerateTransparencyAndComposition);
m_FsrAutoTcrParams = FindProperty(x => x.superResolution.generateTransparencyAndCompositionParameters);
m_FsrTcrMaskTexture = FindProperty(x => x.superResolution.transparencyAndCompositionMask);
m_FogEnabled = FindProperty(x => x.fog.enabled); m_FogEnabled = FindProperty(x => x.fog.enabled);
m_FogExcludeSkybox = FindProperty(x => x.fog.excludeSkybox); m_FogExcludeSkybox = FindProperty(x => x.fog.excludeSkybox);
@ -230,6 +232,7 @@ namespace UnityEditor.Rendering.PostProcessing
EditorGUILayout.PropertyField(m_FsrQualityMode); EditorGUILayout.PropertyField(m_FsrQualityMode);
EditorGUILayout.PropertyField(m_FsrPerformSharpen); EditorGUILayout.PropertyField(m_FsrPerformSharpen);
EditorGUILayout.PropertyField(m_FsrSharpness); EditorGUILayout.PropertyField(m_FsrSharpness);
EditorGUILayout.PropertyField(m_FsrVelocityFactor);
EditorGUILayout.PropertyField(m_FsrExposureSource); EditorGUILayout.PropertyField(m_FsrExposureSource);
if (m_FsrExposureSource.intValue == (int)Upscaling.ExposureSource.Manual) EditorGUILayout.PropertyField(m_FsrExposureTexture); if (m_FsrExposureSource.intValue == (int)Upscaling.ExposureSource.Manual) EditorGUILayout.PropertyField(m_FsrExposureTexture);
EditorGUILayout.PropertyField(m_FsrPreExposure); EditorGUILayout.PropertyField(m_FsrPreExposure);

1
Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset

@ -127,7 +127,6 @@ MonoBehaviour:
multiScaleAORender: {fileID: 7200000, guid: 34a460e8a2e66c243a9c12024e5a798d, type: 3} multiScaleAORender: {fileID: 7200000, guid: 34a460e8a2e66c243a9c12024e5a798d, type: 3}
multiScaleAOUpsample: {fileID: 7200000, guid: 600d6212b59bb40409d19d750b5fd1e9, type: 3} multiScaleAOUpsample: {fileID: 7200000, guid: 600d6212b59bb40409d19d750b5fd1e9, type: 3}
gaussianDownsample: {fileID: 7200000, guid: 6dba4103d23a7904fbc49099355aff3e, type: 3} gaussianDownsample: {fileID: 7200000, guid: 6dba4103d23a7904fbc49099355aff3e, type: 3}
casSharpening: {fileID: 7200000, guid: 00e3ffafadd35564780d8a12adcbeff7, type: 3}
fsr2Upscaler: fsr2Upscaler:
computeLuminancePyramidPass: {fileID: 7200000, guid: 04c3480675e29a340808141e68d4cc8b, type: 3} computeLuminancePyramidPass: {fileID: 7200000, guid: 04c3480675e29a340808141e68d4cc8b, type: 3}
reconstructPreviousDepthPass: {fileID: 7200000, guid: 5060dfafe45aa67459629186ceb7464e, type: 3} reconstructPreviousDepthPass: {fileID: 7200000, guid: 5060dfafe45aa67459629186ceb7464e, type: 3}

16
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs

@ -13,11 +13,8 @@ namespace UnityEngine.Rendering.PostProcessing
public enum UpscalerType public enum UpscalerType
{ {
[InspectorName("FidelityFX Super Resolution 2.2 (FSR2)")] FSR2,
[InspectorName("FidelityFX Super Resolution 2.3 (FSR2)")] FSR2,
[InspectorName("FidelityFX Super Resolution 3.1 (FSR3)")] FSR3, [InspectorName("FidelityFX Super Resolution 3.1 (FSR3)")] FSR3,
//[InspectorName("Arm Accuracy Super Resolution (ASR)")] ASR,
//[InspectorName("Snapdragon Game Super Resolution 2 (SGSR2)")] SGSR2,
[InspectorName("PlayStation Spectral Super Resolution (PSSR)")] PSSR,
} }
[Tooltip("Which upscaling technology to use.")] [Tooltip("Which upscaling technology to use.")]
@ -31,6 +28,9 @@ namespace UnityEngine.Rendering.PostProcessing
[Tooltip("Strength of the sharpening effect.")] [Tooltip("Strength of the sharpening effect.")]
[Range(0, 1)] public float sharpness = 0.8f; [Range(0, 1)] public float sharpness = 0.8f;
[Tooltip("Adjust the influence of motion vectors on temporal accumulation.")]
[Range(0, 1)] public float velocityFactor = 1.0f;
[Tooltip("Choose where to get the exposure value from. Use auto-exposure from either the upscaler or Unity, provide a manual exposure texture, or use a default value.")] [Tooltip("Choose where to get the exposure value from. Use auto-exposure from either the upscaler or Unity, provide a manual exposure texture, or use a default value.")]
public ExposureSource exposureSource = ExposureSource.Auto; 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.")] [Tooltip("Value by which the input signal will be divided, to get back to the original signal produced by the game.")]
@ -218,19 +218,13 @@ namespace UnityEngine.Rendering.PostProcessing
} }
} }
private int _frameIndex;
private void ApplyJitter(Camera camera) private void ApplyJitter(Camera camera)
{ {
var scaledRenderSize = GetScaledRenderSize(camera); var scaledRenderSize = GetScaledRenderSize(camera);
// Stop frame debugger from freaking out
if (Time.deltaTime > 0)
_frameIndex++;
// Perform custom jittering of the camera's projection matrix according to FSR's recipe // Perform custom jittering of the camera's projection matrix according to FSR's recipe
int jitterPhaseCount = Fsr2.GetJitterPhaseCount(scaledRenderSize.x, _upscaleSize.x); int jitterPhaseCount = Fsr2.GetJitterPhaseCount(scaledRenderSize.x, _upscaleSize.x);
Fsr2.GetJitterOffset(out float jitterX, out float jitterY, _frameIndex, jitterPhaseCount);
Fsr2.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount);
JitterOffset = new Vector2(jitterX, jitterY); JitterOffset = new Vector2(jitterX, jitterY);

2
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR2Upscaler.cs

@ -26,8 +26,6 @@ namespace UnityEngine.Rendering.PostProcessing
public override void DestroyContext() public override void DestroyContext()
{ {
base.DestroyContext();
if (_fsrContext != null) if (_fsrContext != null)
{ {
_fsrContext.Destroy(); _fsrContext.Destroy();

3
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3Upscaler.cs

@ -26,8 +26,6 @@ namespace UnityEngine.Rendering.PostProcessing
public override void DestroyContext() public override void DestroyContext()
{ {
base.DestroyContext();
if (_fsrContext != null) if (_fsrContext != null)
{ {
_fsrContext.Destroy(); _fsrContext.Destroy();
@ -90,6 +88,7 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription.CameraFar = camera.farClipPlane; _dispatchDescription.CameraFar = camera.farClipPlane;
_dispatchDescription.CameraFovAngleVertical = camera.fieldOfView * Mathf.Deg2Rad; _dispatchDescription.CameraFovAngleVertical = camera.fieldOfView * Mathf.Deg2Rad;
_dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity _dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity
_dispatchDescription.VelocityFactor = config.velocityFactor;
_dispatchDescription.Reset = config.Reset; _dispatchDescription.Reset = config.Reset;
// Set up the parameters for the optional experimental auto-TCR feature // Set up the parameters for the optional experimental auto-TCR feature

193
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Upscaler.cs

@ -1,8 +1,4 @@
using System; using System;
using System.Runtime.InteropServices;
using FidelityFX;
using FidelityFX.FSR2;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.PostProcessing namespace UnityEngine.Rendering.PostProcessing
{ {
@ -10,195 +6,8 @@ namespace UnityEngine.Rendering.PostProcessing
{ {
public abstract void CreateContext(PostProcessRenderContext context, Upscaling config); public abstract void CreateContext(PostProcessRenderContext context, Upscaling config);
public virtual void DestroyContext()
{
DestroyRenderTexture(ref _reactiveMask);
DestroyConstantsBuffer(ref _reactiveMaskConstants);
DestroyConstantsBuffer(ref _sharpeningConstants);
}
public abstract void DestroyContext();
public abstract void Render(PostProcessRenderContext context, Upscaling config); public abstract void Render(PostProcessRenderContext context, Upscaling config);
private ConstantsBuffer<GenerateReactiveConstants> _reactiveMaskConstants;
private RenderTexture _reactiveMask;
/// <summary>
/// Generalized standalone version of the FSR2 reactive mask auto-generating pass that can be used without needing an active FSR2 context.
/// This allows auto-generated reactive masks to be reused for other non-FSR upscaling techniques.
/// </summary>
protected Texture GenerateReactiveMask(CommandBuffer cmd, PostProcessRenderContext context, Upscaling config, GraphicsFormat format = GraphicsFormat.R8_UNorm)
{
ComputeShader shader = context.resources.computeShaders.fsr2Upscaler?.autoGenReactivePass;
if (shader == null)
return Texture2D.blackTexture;
_reactiveMaskConstants ??= ConstantsBuffer<GenerateReactiveConstants>.Create();
if (_reactiveMask == null)
{
// Use a persistent RT so it can easily be passed to native render plugins
CreateRenderTexture(ref _reactiveMask, "Reactive Mask", config.MaxRenderSize, format, true);
}
Vector2Int scaledRenderSize = config.GetScaledRenderSize(context.camera);
const int threadGroupWorkRegionDim = 8;
int dispatchX = (scaledRenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchY = (scaledRenderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
cmd.BeginSample("Generate Reactive Mask");
_reactiveMaskConstants.Value.scale = config.generateReactiveParameters.scale;
_reactiveMaskConstants.Value.threshold = config.generateReactiveParameters.cutoffThreshold;
_reactiveMaskConstants.Value.binaryValue = config.generateReactiveParameters.binaryValue;
_reactiveMaskConstants.Value.flags = (uint)config.generateReactiveParameters.flags;
_reactiveMaskConstants.UpdateBufferData(cmd);
int kernelIndex = shader.FindKernel("CS");
cmd.SetComputeTextureParam(shader, kernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, config.ColorOpaqueOnly);
cmd.SetComputeTextureParam(shader, kernelIndex, Fsr2ShaderIDs.SrvInputColor, context.source);
cmd.SetComputeTextureParam(shader, kernelIndex, Fsr2ShaderIDs.UavAutoReactive, _reactiveMask);
cmd.SetComputeConstantBufferParam(shader, Fsr2ShaderIDs.CbGenReactive, _reactiveMaskConstants, 0, Marshal.SizeOf<GenerateReactiveConstants>());
cmd.DispatchCompute(shader, kernelIndex, dispatchX, dispatchY, 1);
cmd.EndSample("Generate Reactive Mask");
return _reactiveMask;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct GenerateReactiveConstants
{
public float scale;
public float threshold;
public float binaryValue;
public uint flags;
}
private ConstantsBuffer<CasConstants> _sharpeningConstants;
private static readonly int CasInputColor = Shader.PropertyToID("r_input_color");
private static readonly int CasOutputColor = Shader.PropertyToID("rw_output_color");
private static readonly int CasConstantBuffer = Shader.PropertyToID("cbCAS");
/// <summary>
/// Generalized standalone version of the CAS sharpening filter that can be applied after any non-FSR upscaling technique.
/// </summary>
protected void ApplySharpening(CommandBuffer cmd, PostProcessRenderContext context, in Vector2Int imageSize, float sharpness, RenderTargetIdentifier input, RenderTargetIdentifier output)
{
ComputeShader shader = context.resources.computeShaders.casSharpening;
if (shader == null)
{
cmd.CopyTexture(input, output);
return;
}
const int threadGroupWorkRegionDimRcas = 16;
int threadGroupsX = (imageSize.x + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
int threadGroupsY = (imageSize.y + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
cmd.BeginSample("CAS Sharpening");
// Compute the constants
_sharpeningConstants ??= ConstantsBuffer<CasConstants>.Create();
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(sharpness) * (CasConfigs.Length - 1));
_sharpeningConstants.Value = CasConfigs[sharpnessIndex];
_sharpeningConstants.UpdateBufferData(cmd);
// Dispatch CAS
int kernelIndex = shader.FindKernel("CS");
cmd.SetComputeTextureParam(shader, kernelIndex, CasInputColor, input);
cmd.SetComputeTextureParam(shader, kernelIndex, CasOutputColor, output);
cmd.SetComputeConstantBufferParam(shader, CasConstantBuffer, _sharpeningConstants, 0, Marshal.SizeOf<CasConstants>());
cmd.DispatchCompute(shader, kernelIndex, threadGroupsX, threadGroupsY, 1);
cmd.EndSample("CAS Sharpening");
}
[Serializable, StructLayout(LayoutKind.Sequential)]
private struct CasConstants
{
public CasConstants(uint sharpness, uint halfSharp)
{
// Since we don't use CAS for scaling, most of these values end up being constants
scaling0 = scaling1 = 1065353216;
scaling2 = scaling3 = 0;
sharpness0 = sharpness;
sharpness1 = halfSharp;
sharpness2 = 1090519040;
sharpness3 = 0;
}
public readonly uint scaling0;
public readonly uint scaling1;
public readonly uint scaling2;
public readonly uint scaling3;
public readonly uint sharpness0;
public readonly uint sharpness1;
public readonly uint sharpness2;
public readonly uint sharpness3;
}
/// <summary>
/// The FidelityFX C++ codebase uses floats bitwise converted to ints to pass sharpness parameters to the CAS shader.
/// This is not possible in C# without enabling unsafe code compilation, so to avoid that we instead use a table of precomputed values.
/// </summary>
private static readonly CasConstants[] CasConfigs =
{
new(3187671040u, 45056u),
new(3187831332u, 45075u),
new(3187997869u, 45095u),
new(3188171023u, 45117u),
new(3188351197u, 45139u),
new(3188538827u, 45161u),
new(3188734385u, 45185u),
new(3188938384u, 45210u),
new(3189151382u, 45236u),
new(3189373991u, 45263u),
new(3189606873u, 45292u),
new(3189850757u, 45322u),
new(3190106443u, 45353u),
new(3190374807u, 45386u),
new(3190656816u, 45420u),
new(3190953540u, 45456u),
new(3191266159u, 45494u),
new(3191595985u, 45535u),
new(3191944482u, 45577u),
new(3192313280u, 45622u),
new(3192704205u, 45670u),
};
protected bool CreateRenderTexture(ref RenderTexture rt, string name, in Vector2Int size, GraphicsFormat format, bool enableRandomWrite = false)
{
rt = new RenderTexture(size.x, size.y, 0, format) { name = name, enableRandomWrite = enableRandomWrite };
return rt.Create();
}
protected bool CreateRenderTexture(ref RenderTexture rt, string name, in Vector2Int size, RenderTextureFormat format, bool enableRandomWrite = false)
{
rt = new RenderTexture(size.x, size.y, 0, format) { name = name, enableRandomWrite = enableRandomWrite };
return rt.Create();
}
protected void DestroyRenderTexture(ref RenderTexture rt)
{
if (rt == null)
return;
rt.Release();
rt = null;
}
protected void DestroyConstantsBuffer<TConst>(ref ConstantsBuffer<TConst> cb)
where TConst: struct
{
if (cb == null)
return;
cb.Destroy();
cb = null;
}
} }
} }

37
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine.Assertions; using UnityEngine.Assertions;
using UnityEngine.Serialization;
namespace UnityEngine.Rendering.PostProcessing namespace UnityEngine.Rendering.PostProcessing
{ {
@ -100,7 +99,7 @@ namespace UnityEngine.Rendering.PostProcessing
/// <summary> /// <summary>
/// Advanced upscaling & anti-aliasing settings for this camera. /// Advanced upscaling & anti-aliasing settings for this camera.
/// </summary> /// </summary>
public Upscaling upscaling;
public Upscaling superResolution;
/// <summary> /// <summary>
/// Subpixel Morphological Anti-aliasing settings for this camera. /// Subpixel Morphological Anti-aliasing settings for this camera.
@ -302,7 +301,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive())
{ {
// Set the camera back to its original parameters, so we can output at full display resolution // Set the camera back to its original parameters, so we can output at full display resolution
upscaling.ResetCameraViewport(m_CurrentContext);
superResolution.ResetCameraViewport(m_CurrentContext);
// Blit the upscaled image to the backbuffer // Blit the upscaled image to the backbuffer
if (m_originalTargetTexture != null) if (m_originalTargetTexture != null)
@ -342,7 +341,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (resources != null) m_Resources = resources; if (resources != null) m_Resources = resources;
RuntimeUtilities.CreateIfNull(ref temporalAntialiasing); RuntimeUtilities.CreateIfNull(ref temporalAntialiasing);
RuntimeUtilities.CreateIfNull(ref upscaling);
RuntimeUtilities.CreateIfNull(ref superResolution);
RuntimeUtilities.CreateIfNull(ref subpixelMorphologicalAntialiasing); RuntimeUtilities.CreateIfNull(ref subpixelMorphologicalAntialiasing);
RuntimeUtilities.CreateIfNull(ref fastApproximateAntialiasing); RuntimeUtilities.CreateIfNull(ref fastApproximateAntialiasing);
RuntimeUtilities.CreateIfNull(ref dithering); RuntimeUtilities.CreateIfNull(ref dithering);
@ -445,7 +444,7 @@ namespace UnityEngine.Rendering.PostProcessing
} }
temporalAntialiasing.Release(); temporalAntialiasing.Release();
upscaling.Release();
superResolution.Release();
m_LogHistogram.Release(); m_LogHistogram.Release();
foreach (var bundle in m_Bundles.Values) foreach (var bundle in m_Bundles.Values)
@ -635,13 +634,13 @@ namespace UnityEngine.Rendering.PostProcessing
// Modify internal rendering resolution for both the camera and the pre-upscaling post-processing effects // Modify internal rendering resolution for both the camera and the pre-upscaling post-processing effects
if (context.IsSuperResolutionActive()) if (context.IsSuperResolutionActive())
{ {
upscaling.ConfigureCameraViewport(context);
context.SetRenderSize(upscaling.MaxRenderSize);
superResolution.ConfigureCameraViewport(context);
context.SetRenderSize(superResolution.MaxRenderSize);
} }
else else
{ {
// Ensure all of FSR2's resources are released when it's not in use // Ensure all of FSR2's resources are released when it's not in use
upscaling.Release();
superResolution.Release();
if (m_originalTargetTexture != null) if (m_originalTargetTexture != null)
{ {
@ -740,9 +739,9 @@ namespace UnityEngine.Rendering.PostProcessing
} }
// Create a copy of the opaque-only color buffer for auto-reactive mask generation // Create a copy of the opaque-only color buffer for auto-reactive mask generation
if (context.IsSuperResolutionActive() && (upscaling.autoGenerateReactiveMask || upscaling.autoGenerateTransparencyAndComposition))
if (context.IsSuperResolutionActive() && (superResolution.autoGenerateReactiveMask || superResolution.autoGenerateTransparencyAndComposition))
{ {
Vector2Int scaledRenderSize = upscaling.GetScaledRenderSize(context.camera);
Vector2Int scaledRenderSize = superResolution.GetScaledRenderSize(context.camera);
m_opaqueOnly = context.GetScreenSpaceTemporaryRT(colorFormat: sourceFormat, widthOverride: scaledRenderSize.x, heightOverride: scaledRenderSize.y); m_opaqueOnly = context.GetScreenSpaceTemporaryRT(colorFormat: sourceFormat, widthOverride: scaledRenderSize.x, heightOverride: scaledRenderSize.y);
m_LegacyCmdBufferOpaque.BuiltinBlit(cameraTarget, m_opaqueOnly); m_LegacyCmdBufferOpaque.BuiltinBlit(cameraTarget, m_opaqueOnly);
} }
@ -776,7 +775,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive())
{ {
var displaySize = upscaling.UpscaleSize;
var displaySize = superResolution.UpscaleSize;
m_upscaledOutput = context.GetScreenSpaceTemporaryRT(widthOverride: displaySize.x, heightOverride: displaySize.y); m_upscaledOutput = context.GetScreenSpaceTemporaryRT(widthOverride: displaySize.x, heightOverride: displaySize.y);
context.destination = m_upscaledOutput; context.destination = m_upscaledOutput;
} }
@ -813,7 +812,7 @@ namespace UnityEngine.Rendering.PostProcessing
// Set the camera back to its original parameters, so we can output at full display resolution // Set the camera back to its original parameters, so we can output at full display resolution
if (finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) if (finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive())
{ {
upscaling.ResetCameraViewport(m_CurrentContext);
superResolution.ResetCameraViewport(m_CurrentContext);
} }
if (m_CurrentContext.IsTemporalAntialiasingActive() || m_CurrentContext.IsSuperResolutionActive()) if (m_CurrentContext.IsTemporalAntialiasingActive() || m_CurrentContext.IsSuperResolutionActive())
@ -936,7 +935,7 @@ namespace UnityEngine.Rendering.PostProcessing
flags |= temporalAntialiasing.GetCameraFlags(); flags |= temporalAntialiasing.GetCameraFlags();
if (context.IsSuperResolutionActive()) if (context.IsSuperResolutionActive())
flags |= upscaling.GetCameraFlags();
flags |= superResolution.GetCameraFlags();
if (fog.IsEnabledAndSupported(context)) if (fog.IsEnabledAndSupported(context))
flags |= fog.GetCameraFlags(); flags |= fog.GetCameraFlags();
@ -958,7 +957,7 @@ namespace UnityEngine.Rendering.PostProcessing
bundle.Value.ResetHistory(); bundle.Value.ResetHistory();
temporalAntialiasing.ResetHistory(); temporalAntialiasing.ResetHistory();
upscaling.ResetHistory();
superResolution.ResetHistory();
} }
/// <summary> /// <summary>
@ -1020,7 +1019,7 @@ namespace UnityEngine.Rendering.PostProcessing
context.debugLayer = debugLayer; context.debugLayer = debugLayer;
context.antialiasing = antialiasingMode; context.antialiasing = antialiasingMode;
context.temporalAntialiasing = temporalAntialiasing; context.temporalAntialiasing = temporalAntialiasing;
context.upscaling = upscaling;
context.upscaling = superResolution;
context.logHistogram = m_LogHistogram; context.logHistogram = m_LogHistogram;
#if UNITY_2018_2_OR_NEWER #if UNITY_2018_2_OR_NEWER
@ -1195,17 +1194,17 @@ namespace UnityEngine.Rendering.PostProcessing
} }
else if (context.IsSuperResolutionActive()) else if (context.IsSuperResolutionActive())
{ {
upscaling.ConfigureJitteredProjectionMatrix(context);
superResolution.ConfigureJitteredProjectionMatrix(context);
// Set the upscaler's output to full display resolution, as well as for all following post-processing effects // Set the upscaler's output to full display resolution, as well as for all following post-processing effects
context.SetRenderSize(upscaling.UpscaleSize);
context.SetRenderSize(superResolution.UpscaleSize);
var upscaleTarget = m_TargetPool.Get(); var upscaleTarget = m_TargetPool.Get();
var finalDestination = context.destination; var finalDestination = context.destination;
context.GetScreenSpaceTemporaryRT(cmd, upscaleTarget, 0, context.sourceFormat, isUpscaleOutput: true); context.GetScreenSpaceTemporaryRT(cmd, upscaleTarget, 0, context.sourceFormat, isUpscaleOutput: true);
context.destination = upscaleTarget; context.destination = upscaleTarget;
upscaling.ColorOpaqueOnly = m_opaqueOnly;
upscaling.Render(context);
superResolution.ColorOpaqueOnly = m_opaqueOnly;
superResolution.Render(context);
context.source = upscaleTarget; context.source = upscaleTarget;
context.destination = finalDestination; context.destination = finalDestination;

6
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs

@ -1,7 +1,6 @@
using System; using System;
using FidelityFX.FSR2; using FidelityFX.FSR2;
using FidelityFX.FSR3; using FidelityFX.FSR3;
using UnityEngine.Serialization;
namespace UnityEngine.Rendering.PostProcessing namespace UnityEngine.Rendering.PostProcessing
{ {
@ -216,11 +215,6 @@ namespace UnityEngine.Rendering.PostProcessing
/// </summary> /// </summary>
public ComputeShader gaussianDownsample; public ComputeShader gaussianDownsample;
/// <summary>
/// The compute shader used by the CAS sharpening filter.
/// </summary>
public ComputeShader casSharpening;
/// <summary> /// <summary>
/// Compute shaders used by the FidelityFX Super Resolution 2 (FSR2) Upscaler. /// Compute shaders used by the FidelityFX Super Resolution 2 (FSR2) Upscaler.
/// </summary> /// </summary>

2
Packages/com.unity.postprocessing@3.2.2/package.json

@ -6,6 +6,6 @@
"description": "The post-processing stack (v2) comes with a collection of effects and image filters you can apply to your cameras to improve the visuals of your games.", "description": "The post-processing stack (v2) comes with a collection of effects and image filters you can apply to your cameras to improve the visuals of your games.",
"dependencies": { "dependencies": {
"com.unity.modules.physics": "1.0.0", "com.unity.modules.physics": "1.0.0",
"fidelityfx.fsr": "1.0.0"
"fidelityfx.fsr": "1.0.1"
} }
} }

2
Packages/fidelityfx.fsr

@ -1 +1 @@
Subproject commit d65cc3a35de270a1011c8158810e3d56c579953f
Subproject commit a7d26354776f2f1a31832a9b06b76c284de8a568

2
Packages/packages-lock.json

@ -82,7 +82,7 @@
"source": "embedded", "source": "embedded",
"dependencies": { "dependencies": {
"com.unity.modules.physics": "1.0.0", "com.unity.modules.physics": "1.0.0",
"fidelityfx.fsr": "1.0.0"
"fidelityfx.fsr": "1.0.1"
} }
}, },
"com.unity.settings-manager": { "com.unity.settings-manager": {

Loading…
Cancel
Save