@ -28,18 +28,41 @@ using FidelityFX;
namespace UnityEngine.Rendering.PostProcessing
{
[UnityEngine.Scripting.Preserve]
[Serializable]
public class Fsr2QualityModeParameter : ParameterOverride < Fsr2 . QualityMode >
public class SuperResolution
{
}
public static Func < PostProcessRenderContext , IFsr2Callbacks > CallbacksFactory { get ; set ; } = ( context ) = > new Callbacks ( context . resources ) ;
[Tooltip("Standard scaling ratio presets.")]
public Fsr2 . QualityMode qualityMode = Fsr2 . QualityMode . Quality ;
[Tooltip("Apply RCAS sharpening to the image after upscaling.")]
public bool performSharpenPass = true ;
[Tooltip("Strength of the sharpening effect.")]
[Range(0, 1)] public float sharpness = 0.8f ;
[Tooltip("Allow the use of half precision compute operations, potentially improving performance if the platform supports it.")]
public bool enableFP16 = false ;
[Tooltip("Allow an exposure value to be computed internally. When set to false, either the provided exposure texture or a default exposure value will be used.")]
public bool enableAutoExposure = true ;
[Tooltip("Value by which the input signal will be divided, to get back to the original signal produced by the game.")]
public float preExposure = 1.0f ;
[Tooltip("Optional 1x1 texture containing the exposure value for the current frame.")]
public Texture exposure = null ;
[Tooltip("Optional texture to control the influence of the current frame on the reconstructed output. If unset, either an auto-generated or a default cleared reactive mask will be used.")]
public Texture reactiveMask = null ;
[Tooltip("Optional texture for marking areas of specialist rendering which should be accounted for during the upscaling process. If unset, a default cleared mask will be used.")]
public Texture transparencyAndCompositionMask = null ;
[Tooltip("Automatically generate a reactive mask based on the difference between opaque-only render output and the final render output including alpha transparencies.")]
public bool autoGenerateReactiveMask = true ;
[Tooltip("Parameters to control the process of auto-generating a reactive mask.")]
public GenerateReactiveParameters generateReactiveParameters = new GenerateReactiveParameters ( ) ;
[Serializable]
public class Fsr2GenerateReactiveParameters : ParameterOverride < Fsr2GenerateReactiveParams >
{
}
[Serializable]
public class Fsr2GenerateReactiveParams
public class GenerateReactiveParameters
{
[Range(0, 2)] public float scale = 0.5f ;
[Range(0, 1)] public float cutoffThreshold = 0.2f ;
@ -47,29 +70,6 @@ namespace UnityEngine.Rendering.PostProcessing
public Fsr2 . GenerateReactiveFlags flags = Fsr2 . GenerateReactiveFlags . ApplyTonemap | Fsr2 . GenerateReactiveFlags . ApplyThreshold | Fsr2 . GenerateReactiveFlags . UseComponentsMax ;
}
[UnityEngine.Scripting.Preserve]
[Serializable]
public class SuperResolution
{
public Fsr2QualityModeParameter qualityMode = new Fsr2QualityModeParameter ( ) { value = Fsr2 . QualityMode . Quality } ;
public BoolParameter performSharpenPass = new BoolParameter ( ) { value = true } ;
[Range(0, 1)] public FloatParameter sharpness = new FloatParameter ( ) { value = 0.8f } ;
[Tooltip("Allow the use of half precision compute operations, potentially improving performance")]
public BoolParameter enableFP16 = new BoolParameter ( ) { value = false } ;
[Header("Exposure")]
public BoolParameter enableAutoExposure = new BoolParameter ( ) { value = true } ;
public FloatParameter preExposure = new FloatParameter ( ) { value = 1.0f } ;
public TextureParameter exposure = new TextureParameter ( ) { value = null } ;
[Header("Reactivity, Transparency & Composition")]
public TextureParameter reactiveMask = new TextureParameter ( ) { value = null } ;
public TextureParameter transparencyAndCompositionMask = new TextureParameter ( ) { value = null } ;
public BoolParameter autoGenerateReactiveMask = new BoolParameter ( ) { value = true } ;
public Fsr2GenerateReactiveParameters generateReactiveParameters = new Fsr2GenerateReactiveParameters ( ) ;
public Vector2 jitter { get ; private set ; }
private Fsr2Context _fsrContext ;
@ -106,13 +106,7 @@ namespace UnityEngine.Rendering.PostProcessing
public void Render ( PostProcessRenderContext context )
{
var cmd = context . command ;
if ( ! Application . isPlaying )
{
// We don't want this effect to start injecting scripts in edit mode, so just blit and skip the rest entirely
cmd . BlitFullscreenTriangle ( context . source , context . destination ) ;
return ;
}
cmd . BeginSample ( "FSR2" ) ;
// Monitor for any resolution changes and recreate the FSR2 context if necessary
// We can't create an FSR2 context without info from the post-processing context, so delay the initial setup until here
@ -143,6 +137,9 @@ namespace UnityEngine.Rendering.PostProcessing
cmd . BlitFullscreenTriangle ( Fsr2ShaderIDs . UavUpscaledOutput , context . destination ) ;
cmd . ReleaseTemporaryRT ( Fsr2ShaderIDs . UavUpscaledOutput ) ;
cmd . EndSample ( "FSR2" ) ;
_reset = false ;
}
private void CreateFsrContext ( PostProcessRenderContext context )
@ -161,7 +158,7 @@ namespace UnityEngine.Rendering.PostProcessing
if ( enableFP16 ) flags | = Fsr2 . InitializationFlags . EnableFP16Usage ;
if ( enableAutoExposure ) flags | = Fsr2 . InitializationFlags . EnableAutoExposure ;
_fsrContext = Fsr2 . CreateContext ( _displaySize , _renderSize , new Callbacks ( context . resources ) , flags ) ;
_fsrContext = Fsr2 . CreateContext ( _displaySize , _renderSize , CallbacksFactory ( context ) , flags ) ;
// Apply a mipmap bias so that textures retain their sharpness
float biasOffset = Fsr2 . GetMipmapBiasOffset ( _renderSize . x , _displaySize . x ) ;
@ -213,9 +210,9 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription . Reactive = null ;
_dispatchDescription . TransparencyAndComposition = null ;
if ( ! enableAutoExposure & & exposure . value ! = null ) _dispatchDescription . Exposure = exposure . valu e ;
if ( reactiveMask . value ! = null ) _dispatchDescription . Reactive = reactiveMask . value ;
if ( transparencyAndCompositionMask . value ! = null ) _dispatchDescription . TransparencyAndComposition = transparencyAndCompositionMask . value ;
if ( ! enableAutoExposure & & exposure ! = null ) _dispatchDescription . Exposure = exposure ;
if ( reactiveMask ! = null ) _dispatchDescription . Reactive = reactiveMask ;
if ( transparencyAndCompositionMask ! = null ) _dispatchDescription . TransparencyAndComposition = transparencyAndCompositionMask ;
_dispatchDescription . Output = null ;
_dispatchDescription . PreExposure = preExposure ;
@ -230,7 +227,6 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription . CameraFovAngleVertical = camera . fieldOfView * Mathf . Deg2Rad ;
_dispatchDescription . ViewSpaceToMetersFactor = 1.0f ; // 1 unit is 1 meter in Unity
_dispatchDescription . Reset = _reset ;
_reset = false ;
if ( SystemInfo . usesReversedZBuffer )
{