@ -18,8 +18,7 @@ namespace UnityEngine.Rendering.PostProcessing
private RenderTexture _inputColor ;
private readonly RenderTexture [ ] _inputDepth = new RenderTexture [ 2 ] ;
private readonly RenderTexture [ ] _inputMotionVectors = new RenderTexture [ 2 ] ;
private RenderTexture _outputColor ;
private Texture2D _outputIntermediate ;
private Texture2D _outputColor ;
private bool _contextInitialized ;
private uint _frameCount ;
@ -53,15 +52,14 @@ namespace UnityEngine.Rendering.PostProcessing
initParams . autoKeepCopies = 0 u ; // We use double buffered depth and motion vector copies created by Unity
CreateRenderTexture ( ref _inputColor , "PSSR Input Color" , config . MaxRenderSize , context . sourceFormat , true ) ;
CreateRenderTextureArray ( _inputDepth , "PSSR Input Depth" , config . MaxRenderSize , GraphicsFormat . R32_SFloat , true ) ;
CreateRenderTextureArray ( _inputDepth , "PSSR Input Depth" , config . MaxRenderSize , GraphicsFormat . R32_SFloat , true ) ;
CreateRenderTextureArray ( _inputMotionVectors , "PSSR Input Motion Vectors" , config . MaxRenderSize , GraphicsFormat . R16G16_SFloat , true ) ;
CreateRenderTexture ( ref _outputColor , "PSSR Output Color" , config . UpscaleSize , RenderTextureFormat . RGB111110Float ) ;
if ( PSSRPlugin . CreatePssrContext ( ref initParams , out IntPtr outputColorTexturePtr ) > = 0 & & outputColorTexturePtr ! = IntPtr . Zero )
{
// PSSR requires an output color texture in a very particular format (k11_11_10Float with kStandard256B tile mode and a specific alignment) that Unity cannot create directly.
// So instead we let the plugin create that texture and then import it into Unity as a generic 32bpp texture from a native pointer.
_outputIntermediate = Texture2D . CreateExternalTexture ( config . UpscaleSize . x , config . UpscaleSize . y , TextureFormat . RGBA32 , false , true , outputColorTexturePtr ) ;
_outputColor = Texture2D . CreateExternalTexture ( config . UpscaleSize . x , config . UpscaleSize . y , TextureFormat . RGBA32 , false , true , outputColorTexturePtr ) ;
_dispatchParamsBuffer = Marshal . AllocHGlobal ( Marshal . SizeOf < PSSRPlugin . DispatchParams > ( ) ) ;
_contextInitialized = true ;
}
@ -87,13 +85,12 @@ namespace UnityEngine.Rendering.PostProcessing
_contextInitialized = false ;
}
if ( _outputIntermediate ! = null )
if ( _outputColor ! = null )
{
Object . Destroy ( _outputIntermediate ) ;
_outputIntermediate = null ;
Object . Destroy ( _outputColor ) ;
_outputColor = null ;
}
DestroyRenderTexture ( ref _outputColor ) ;
DestroyRenderTextureArray ( _inputMotionVectors ) ;
DestroyRenderTextureArray ( _inputDepth ) ;
DestroyRenderTexture ( ref _inputColor ) ;
@ -156,7 +153,7 @@ namespace UnityEngine.Rendering.PostProcessing
_ = > null ,
} ) ;
_dispatchParams . reactiveMask = ToNativePtr ( reactiveMask ) ;
_dispatchParams . outputColor = ToNativePtr ( _outputIntermediate ) ;
_dispatchParams . outputColor = ToNativePtr ( _outputColor ) ;
var scaledRenderSize = config . GetScaledRenderSize ( context . camera ) ;
_dispatchParams . renderWidth = ( uint ) scaledRenderSize . x ;
@ -171,9 +168,6 @@ namespace UnityEngine.Rendering.PostProcessing
Marshal . StructureToPtr ( _dispatchParams , _dispatchParamsBuffer , false ) ;
cmd . IssuePluginEventAndData ( PSSRPlugin . GetRenderEventAndDataFunc ( ) , 1 , _dispatchParamsBuffer ) ;
// Convert the native texture into Unity-land using a blind texture data copy
cmd . CopyTexture ( _outputIntermediate , _outputColor ) ;
if ( config . performSharpenPass )
{
// PSSR output is already pretty sharp, and we don't want to over-sharpen the image, so cut the sharpness range by half