using System; using UnityEngine; namespace FidelityFX { /// /// All the compute shaders used by the FidelityFX Super Resolution 3 (FSR3) Upscaler. /// [Serializable] public class Fsr3UpscalerShaders: ScriptableObject { /// /// The compute shader used by the luminance pyramid computation pass. /// public ComputeShader computeLuminancePyramidPass; /// /// The compute shader used by the previous depth reconstruction pass. /// public ComputeShader reconstructPreviousDepthPass; /// /// The compute shader used by the depth clip pass. /// public ComputeShader depthClipPass; /// /// The compute shader used by the lock pass. /// public ComputeShader lockPass; /// /// The compute shader used by the accumulation pass. /// public ComputeShader accumulatePass; /// /// The compute shader used by the RCAS sharpening pass. /// public ComputeShader sharpenPass; /// /// The compute shader used to auto-generate a reactive mask. /// public ComputeShader autoGenReactivePass; /// /// The compute shader used to auto-generate a transparency & composition mask. /// public ComputeShader tcrAutoGenPass; /// /// Returns a copy of this class and its contents. /// public Fsr3UpscalerShaders Clone() { return (Fsr3UpscalerShaders)MemberwiseClone(); } /// /// 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. /// public Fsr3UpscalerShaders DeepCopy() { Fsr3UpscalerShaders copy = CreateInstance(); 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; } /// /// Destroy all the shaders within this instance. /// Use this only on clones created through DeepCopy. /// 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(assetPath); } #endif } }