FSR2 tests in Unity based on built-in render pipeline
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

119 lines
4.6 KiB

using System;
using UnityEngine;
namespace FidelityFX
{
/// <summary>
/// All the compute shaders used by the FidelityFX Super Resolution 3 (FSR3) Upscaler.
/// </summary>
[Serializable]
public class Fsr3UpscalerShaders: ScriptableObject
{
/// <summary>
/// The compute shader used by the luminance pyramid computation pass.
/// </summary>
public ComputeShader computeLuminancePyramidPass;
/// <summary>
/// The compute shader used by the previous depth reconstruction pass.
/// </summary>
public ComputeShader reconstructPreviousDepthPass;
/// <summary>
/// The compute shader used by the depth clip pass.
/// </summary>
public ComputeShader depthClipPass;
/// <summary>
/// The compute shader used by the lock pass.
/// </summary>
public ComputeShader lockPass;
/// <summary>
/// The compute shader used by the accumulation pass.
/// </summary>
public ComputeShader accumulatePass;
/// <summary>
/// The compute shader used by the RCAS sharpening pass.
/// </summary>
public ComputeShader sharpenPass;
/// <summary>
/// The compute shader used to auto-generate a reactive mask.
/// </summary>
public ComputeShader autoGenReactivePass;
/// <summary>
/// The compute shader used to auto-generate a transparency & composition mask.
/// </summary>
public ComputeShader tcrAutoGenPass;
/// <summary>
/// Returns a copy of this class and its contents.
/// </summary>
public Fsr3UpscalerShaders Clone()
{
return (Fsr3UpscalerShaders)MemberwiseClone();
}
/// <summary>
/// Returns a copy of this class with clones of all its shaders.
/// This can be useful if you're running multiple FSR3 Upscaler instances with different shader configurations.
/// Be sure to clean up these clones through Dispose once you're done with them.
/// </summary>
public Fsr3UpscalerShaders DeepCopy()
{
Fsr3UpscalerShaders copy = CreateInstance<Fsr3UpscalerShaders>();
copy.computeLuminancePyramidPass = Instantiate(computeLuminancePyramidPass);
copy.reconstructPreviousDepthPass = Instantiate(reconstructPreviousDepthPass);
copy.depthClipPass = Instantiate(depthClipPass);
copy.lockPass = Instantiate(lockPass);
copy.accumulatePass = Instantiate(accumulatePass);
copy.sharpenPass = Instantiate(sharpenPass);
copy.autoGenReactivePass = Instantiate(autoGenReactivePass);
copy.tcrAutoGenPass = Instantiate(tcrAutoGenPass);
return copy;
}
/// <summary>
/// Destroy all the shaders within this instance.
/// Use this only on clones created through DeepCopy.
/// </summary>
public void Dispose()
{
Destroy(computeLuminancePyramidPass);
Destroy(reconstructPreviousDepthPass);
Destroy(depthClipPass);
Destroy(lockPass);
Destroy(accumulatePass);
Destroy(sharpenPass);
Destroy(autoGenReactivePass);
Destroy(tcrAutoGenPass);
}
#if UNITY_EDITOR
private void Reset()
{
computeLuminancePyramidPass = FindComputeShader("ffx_fsr3upscaler_compute_luminance_pyramid_pass");
reconstructPreviousDepthPass = FindComputeShader("ffx_fsr3upscaler_reconstruct_previous_depth_pass");
depthClipPass = FindComputeShader("ffx_fsr3upscaler_depth_clip_pass");
lockPass = FindComputeShader("ffx_fsr3upscaler_lock_pass");
accumulatePass = FindComputeShader("ffx_fsr3upscaler_accumulate_pass");
sharpenPass = FindComputeShader("ffx_fsr3upscaler_rcas_pass");
autoGenReactivePass = FindComputeShader("ffx_fsr3upscaler_autogen_reactive_pass");
tcrAutoGenPass = FindComputeShader("ffx_fsr3upscaler_tcr_autogen_pass");
}
private static ComputeShader FindComputeShader(string name)
{
string[] assetGuids = UnityEditor.AssetDatabase.FindAssets($"t:ComputeShader {name}");
if (assetGuids == null || assetGuids.Length == 0)
return null;
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(assetGuids[0]);
return UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>(assetPath);
}
#endif
}
}