From 2d05d08f86a90329681cd663fdda09e1dabf0c5d Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 18 Dec 2023 12:19:25 +0100 Subject: [PATCH] Added the ability to clone the shaders, in case multiple FSR3 instances with different configurations are needed. --- Assets/Scripts/Core/Fsr3UpscalerShaders.cs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Assets/Scripts/Core/Fsr3UpscalerShaders.cs b/Assets/Scripts/Core/Fsr3UpscalerShaders.cs index 8b67a27..6e85b95 100644 --- a/Assets/Scripts/Core/Fsr3UpscalerShaders.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerShaders.cs @@ -56,6 +56,41 @@ namespace FidelityFX { 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()