@ -14,6 +14,7 @@ namespace UnityEngine.Rendering.PostProcessing
private RenderTexture _inputColor ;
private RenderTexture _inputDepth ;
private RenderTexture _inputMotionVectors ;
private RenderTexture _outputColor ;
private Texture2D _outputIntermediate ;
@ -39,6 +40,7 @@ namespace UnityEngine.Rendering.PostProcessing
CreateRenderTexture ( ref _inputColor , "PSSR Input Color" , config . MaxRenderSize , context . sourceFormat , true ) ;
CreateRenderTexture ( ref _inputDepth , "PSSR Input Depth" , config . MaxRenderSize , GraphicsFormat . R32_SFloat , true ) ;
CreateRenderTexture ( ref _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 )
@ -83,8 +85,6 @@ namespace UnityEngine.Rendering.PostProcessing
}
}
private static readonly int CameraMotionVectorsTexture = Shader . PropertyToID ( "_CameraMotionVectorsTexture" ) ;
public override void Render ( PostProcessRenderContext context , Upscaling config )
{
var cmd = context . command ;
@ -97,11 +97,11 @@ namespace UnityEngine.Rendering.PostProcessing
cmd . BeginSample ( "PSSR" ) ;
// TODO: if PSSR needs a copy of the previous depth and motion vectors anyway, why not just double-buffer those resources ourselves and make good use of these otherwise dumb copies?
PrepareInputs ( cmd , context , config , _inputColor , _inputDepth ) ;
PrepareInputs ( cmd , context , config , _inputColor , _inputDepth , _inputMotionVectors ) ;
_dispatchParams . color = ToNativePtr ( _inputColor ) ;
_dispatchParams . depth = ToNativePtr ( _inputDepth ) ;
_dispatchParams . motionVectors = ToNativePtr ( Shader . GetGlobalTexture ( CameraMotionVectorsTexture ) ) ;
_dispatchParams . motionVectors = ToNativePtr ( _inputMotionVectors ) ;
_dispatchParams . exposure = ToNativePtr ( config . exposureSource switch
{
Upscaling . ExposureSource . Manual when config . exposure ! = null = > config . exposure ,
@ -114,7 +114,7 @@ namespace UnityEngine.Rendering.PostProcessing
var scaledRenderSize = config . GetScaledRenderSize ( context . camera ) ;
_dispatchParams . renderWidth = ( uint ) scaledRenderSize . x ;
_dispatchParams . renderHeight = ( uint ) scaledRenderSize . y ;
_dispatchParams . jitter = config . JitterOffset ; // TODO: may need to scale this (should be jitter in render pixels apparently)
_dispatchParams . jitter = config . JitterOffset ;
_dispatchParams . motionVectorScale = new Vector2 ( - scaledRenderSize . x , - scaledRenderSize . y ) ;
_dispatchParams . FromCamera ( context . camera ) ;
_dispatchParams . preExposure = config . preExposure ;
@ -178,7 +178,7 @@ namespace UnityEngine.Rendering.PostProcessing
public Vector2 jitter ;
public Vector2 motionVectorScale ;
public Matrix4x4 camProjection ;
public Matrix4x4 camProjectionNoJitter ;
public Vector3 camForward ;
public Vector3 camUp ;
public Vector3 camRight ;
@ -194,7 +194,7 @@ namespace UnityEngine.Rendering.PostProcessing
public void FromCamera ( Camera cam )
{
camProjection = cam . p rojectionMatrix;
camProjectionNoJitter = cam . nonJitteredP rojectionMatrix;
camForward = cam . transform . forward ;
camUp = cam . transform . up ;
camRight = cam . transform . right ;