|
|
|
@ -4,7 +4,6 @@ using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using FidelityFX; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Experimental.Rendering; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -20,6 +19,9 @@ public class Fsr2Controller : MonoBehaviour |
|
|
|
[SerializeField, Range(0, 1)] |
|
|
|
private float sharpness = 0.8f; |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
private bool reset; |
|
|
|
|
|
|
|
[HideInInspector] |
|
|
|
public Camera gameCamera; |
|
|
|
|
|
|
|
@ -37,7 +39,7 @@ public class Fsr2Controller : MonoBehaviour |
|
|
|
private Fsr2Context _context; |
|
|
|
private readonly Fsr2.DispatchDescription _dispatchDescription = new Fsr2.DispatchDescription(); |
|
|
|
|
|
|
|
private RenderTexture _outputRT; |
|
|
|
private RenderTexture _upscaledOutput; |
|
|
|
|
|
|
|
private Material _copyMotionMat; |
|
|
|
private Material CopyMotionVectorsMaterial |
|
|
|
@ -73,16 +75,16 @@ public class Fsr2Controller : MonoBehaviour |
|
|
|
|
|
|
|
// 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
|
|
|
|
_outputRT = new RenderTexture(DisplaySize.x, DisplaySize.y, 24, RenderTextureFormat.ARGBHalf) { name = "FSR2 Upscaled Output", enableRandomWrite = true }; |
|
|
|
_outputRT.Create(); |
|
|
|
_upscaledOutput = new RenderTexture(DisplaySize.x, DisplaySize.y, 24, RenderTextureFormat.ARGBHalf) { name = "FSR2 Upscaled Output", enableRandomWrite = true }; |
|
|
|
_upscaledOutput.Create(); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnDisable() |
|
|
|
{ |
|
|
|
if (_outputRT != null) |
|
|
|
if (_upscaledOutput != null) |
|
|
|
{ |
|
|
|
_outputRT.Release(); |
|
|
|
_outputRT = null; |
|
|
|
_upscaledOutput.Release(); |
|
|
|
_upscaledOutput = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (_context != null) |
|
|
|
@ -116,7 +118,7 @@ public class Fsr2Controller : MonoBehaviour |
|
|
|
|
|
|
|
_dispatchDescription.ColorDepth = renderBuffer; |
|
|
|
_dispatchDescription.MotionVectors = motionVectors; |
|
|
|
_dispatchDescription.Output = _outputRT; |
|
|
|
_dispatchDescription.Output = _upscaledOutput; |
|
|
|
_dispatchDescription.Exposure = null; |
|
|
|
_dispatchDescription.Reactive = null; |
|
|
|
_dispatchDescription.PreExposure = 0; |
|
|
|
@ -130,6 +132,8 @@ public class Fsr2Controller : MonoBehaviour |
|
|
|
_dispatchDescription.CameraFar = gameCamera.farClipPlane; |
|
|
|
_dispatchDescription.CameraFovAngleVertical = gameCamera.fieldOfView * Mathf.Deg2Rad; |
|
|
|
_dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity
|
|
|
|
_dispatchDescription.Reset = reset; |
|
|
|
reset = false; |
|
|
|
|
|
|
|
_context.Dispatch(_dispatchDescription); |
|
|
|
|
|
|
|
@ -137,6 +141,6 @@ public class Fsr2Controller : MonoBehaviour |
|
|
|
|
|
|
|
// Output upscaled image to screen
|
|
|
|
// TODO: we should probably use a shader to include depth & motion vectors into the output
|
|
|
|
Graphics.Blit(_outputRT, dest); |
|
|
|
Graphics.Blit(_upscaledOutput, dest); |
|
|
|
} |
|
|
|
} |