@ -2,9 +2,7 @@ using System;
using System.Collections ;
using System.Collections.Generic ;
using System.Linq ;
using System.Runtime.InteropServices ;
using FidelityFX ;
using UnityEditor ;
using UnityEngine ;
using UnityEngine.Rendering ;
@ -31,9 +29,10 @@ public class Fsr2Controller : MonoBehaviour
public float renderScale ;
private Fsr2Context _context ;
private readonly Fsr2 . DispatchDescription _dispatchDescription = new Fsr2 . DispatchDescription ( ) ;
private RenderTexture _upscaleRT ;
private RenderTexture _rcasOutput ;
private RenderTexture _outputRT ;
private Texture2D _exposure ;
private Material _testMaterial ;
@ -43,7 +42,7 @@ public class Fsr2Controller : MonoBehaviour
{
if ( _testMaterial = = null )
{
var testShader = Fsr2 . Callbacks . LoadShader ( "FSR2 /FSRTest" ) ;
var testShader = Fsr2 . Global Callbacks. LoadShader ( "Shaders /FSRTest" ) ;
_testMaterial = new Material ( testShader ) ;
}
@ -60,9 +59,9 @@ public class Fsr2Controller : MonoBehaviour
_upscaleRT = new RenderTexture ( Screen . width , Screen . height , 2 4 , RenderTextureFormat . ARGBHalf ) ;
_upscaleRT . Create ( ) ;
_rcasOutput = new RenderTexture ( Screen . width , Screen . height , 2 4 , RenderTextureFormat . ARGBHalf ) ;
_rcasOutput . enableRandomWrite = true ;
_rcasOutput . Create ( ) ;
_outputRT = new RenderTexture ( Screen . width , Screen . height , 2 4 , RenderTextureFormat . ARGBHalf ) ;
_outputRT . enableRandomWrite = true ;
_outputRT . Create ( ) ;
_exposure = new Texture2D ( 1 , 1 ) ;
_exposure . name = "FSR2 Exposure" ;
@ -78,10 +77,10 @@ public class Fsr2Controller : MonoBehaviour
_exposure = null ;
}
if ( _rcasOutput ! = null )
if ( _outputRT ! = null )
{
_rcasOutput . Release ( ) ;
_rcasOutput = null ;
_outputRT . Release ( ) ;
_outputRT = null ;
}
if ( _upscaleRT ! = null )
@ -111,9 +110,22 @@ public class Fsr2Controller : MonoBehaviour
// Do a dumb upscale first
Graphics . Blit ( gameCamera . targetTexture , _upscaleRT , TestMaterial ) ;
_context . Dispatch ( _upscaleRT , _rcasOutput , _exposure , performSharpenPass , sharpness ) ;
_dispatchDescription . Input = _upscaleRT ;
_dispatchDescription . Output = _outputRT ;
_dispatchDescription . Exposure = _exposure ;
_dispatchDescription . PreExposure = 1.0f ;
_dispatchDescription . EnableSharpening = performSharpenPass ;
_dispatchDescription . Sharpness = sharpness ;
_dispatchDescription . MotionVectorScale . x = gameCamera . pixelWidth ;
_dispatchDescription . MotionVectorScale . y = gameCamera . pixelHeight ;
_dispatchDescription . FrameTimeDelta = Time . unscaledDeltaTime ;
_dispatchDescription . CameraNear = gameCamera . nearClipPlane ;
_dispatchDescription . CameraFar = gameCamera . farClipPlane ;
_dispatchDescription . CameraFovAngleVertical = gameCamera . fieldOfView * Mathf . Deg2Rad ;
_context . Dispatch ( _dispatchDescription ) ;
// Output sharpened image to screen
Graphics . Blit ( _rcasOutput , dest ) ;
Graphics . Blit ( _outputRT , dest ) ;
}
}