diff --git a/UnifiedUniversalBlur/Scripts/RenderEmulation.cs b/UnifiedUniversalBlur/Scripts/RenderEmulation.cs deleted file mode 100644 index 3a1bd78..0000000 --- a/UnifiedUniversalBlur/Scripts/RenderEmulation.cs +++ /dev/null @@ -1,52 +0,0 @@ -#if !UNITY_2022_1_OR_NEWER -using UnityEngine; -using UnityEngine.Rendering; - -namespace Unified.Universal.Blur -{ - /// - /// This class is trying to emulate RTHandleNeedsReAlloc from 2022 version of unity - /// - public class RenderEmulation - { - - /// - /// Return true if handle does not match descriptor - /// - /// RTHandle to check (can be null) - /// Descriptor for the RTHandle to match - /// Filtering mode of the RTHandle. - /// Addressing mode of the RTHandle. - /// Set to true if the depth buffer should be used as a shadow map. - /// Anisotropic filtering level. - /// Bias applied to mipmaps during filtering. - /// Name of the RTHandle. - /// Check if the RTHandle has auto scaling enabled if not, check the widths and heights - /// - internal static bool RTHandleNeedsReAlloc(RTHandle handle, in RenderTextureDescriptor descriptor, FilterMode filterMode, TextureWrapMode wrapMode, bool isShadowMap, int anisoLevel, float mipMapBias, string name, bool scaled) - { - if (handle == null || handle.rt == null) - return true; - if (handle.useScaling != scaled) - return true; - if (!scaled && (handle.rt.width != descriptor.width || handle.rt.height != descriptor.height)) - return true; - return handle.rt.descriptor.depthBufferBits != descriptor.depthBufferBits || (handle.rt.descriptor.depthBufferBits == (int)DepthBits.None && !isShadowMap && handle.rt.descriptor.graphicsFormat != descriptor.graphicsFormat) || handle.rt.descriptor.dimension != descriptor.dimension || handle.rt.descriptor.enableRandomWrite != descriptor.enableRandomWrite || handle.rt.descriptor.useMipMap != descriptor.useMipMap || handle.rt.descriptor.autoGenerateMips != descriptor.autoGenerateMips - || handle.rt.descriptor.msaaSamples != descriptor.msaaSamples || handle.rt.descriptor.bindMS != descriptor.bindMS || handle.rt.descriptor.useDynamicScale != descriptor.useDynamicScale || handle.rt.descriptor.memoryless != descriptor.memoryless || handle.rt.filterMode != filterMode || handle.rt.wrapMode != wrapMode || handle.rt.anisoLevel != anisoLevel || handle.rt.mipMapBias != mipMapBias || handle.name != name; - } - - public static bool ReAllocateIfNeeded(ref RTHandle handle, in RenderTextureDescriptor descriptor, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat, bool isShadowMap = false, int anisoLevel = 1, float mipMapBias = 0, string name = "") - { - if (RTHandleNeedsReAlloc(handle, descriptor, filterMode, wrapMode, isShadowMap, anisoLevel, mipMapBias, name, false)) - { - handle?.Release(); - handle = RTHandles.Alloc(descriptor.width, descriptor.height, descriptor.volumeDepth, (DepthBits)descriptor.depthBufferBits, descriptor.graphicsFormat, filterMode, wrapMode, descriptor.dimension, descriptor.enableRandomWrite, descriptor.useMipMap, descriptor.autoGenerateMips, isShadowMap, anisoLevel, mipMapBias, (MSAASamples)descriptor.msaaSamples, descriptor.bindMS, descriptor.useDynamicScale, descriptor.memoryless, name); - return true; - } - - return false; - } - } - -} -#endif \ No newline at end of file diff --git a/UnifiedUniversalBlur/Scripts/RenderEmulation.cs.meta b/UnifiedUniversalBlur/Scripts/RenderEmulation.cs.meta deleted file mode 100644 index b75004d..0000000 --- a/UnifiedUniversalBlur/Scripts/RenderEmulation.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a45a5239c90047cc9f42732a2ce20ccf -timeCreated: 1675558071 \ No newline at end of file diff --git a/UnifiedUniversalBlur/Scripts/UniversalBlurPass.cs b/UnifiedUniversalBlur/Scripts/UniversalBlurPass.cs index 525bb80..2cff910 100644 --- a/UnifiedUniversalBlur/Scripts/UniversalBlurPass.cs +++ b/UnifiedUniversalBlur/Scripts/UniversalBlurPass.cs @@ -9,14 +9,10 @@ class UniversalBlurPass : ScriptableRenderPass { private const string k_GlobalFullScreenBlurTexture = "_GlobalFullScreenBlurTexture"; - private static readonly int m_BlitTextureShaderID = Shader.PropertyToID("_BlitTexture"); private static readonly int m_KawaseOffsetID = Shader.PropertyToID("_KawaseOffset"); private PassData m_PassData; - private RTHandle m_tmpRT1; - private RTHandle m_tmpRT2; - public void Setup(Action passDataOptions, float downsample, in RenderingData renderingData) { m_PassData ??= new PassData(); @@ -30,21 +26,20 @@ public void Setup(Action passDataOptions, float downsample, in Renderi rtDesc.height = Mathf.RoundToInt(rtDesc.height / downsample); #if UNITY_2022_1_OR_NEWER - RenderingUtils.ReAllocateIfNeeded(ref m_tmpRT1, rtDesc, name: "_PassRT1", wrapMode: TextureWrapMode.Clamp); - RenderingUtils.ReAllocateIfNeeded(ref m_tmpRT2, rtDesc, name: "_PassRT2", wrapMode: TextureWrapMode.Clamp); - #else - RenderEmulation.ReAllocateIfNeeded(ref m_tmpRT1, rtDesc, name: "_PassRT1", wrapMode: TextureWrapMode.Clamp); - RenderEmulation.ReAllocateIfNeeded(ref m_tmpRT2, rtDesc, name: "_PassRT2", wrapMode: TextureWrapMode.Clamp); + RenderingUtils.ReAllocateIfNeeded(ref m_PassData.tmpRT1, rtDesc, name: "_PassRT1", wrapMode: TextureWrapMode.Clamp); + RenderingUtils.ReAllocateIfNeeded(ref m_PassData.tmpRT2, rtDesc, name: "_PassRT2", wrapMode: TextureWrapMode.Clamp); #endif - - m_PassData.tmpRT1 = m_tmpRT1; - m_PassData.tmpRT2 = m_tmpRT2; } public void Dispose() { - m_tmpRT1?.Release(); - m_tmpRT2?.Release(); + #if UNITY_2022_1_OR_NEWER + if (m_PassData != null) + { + m_PassData.tmpRT1.Release(); + m_PassData.tmpRT2.Release(); + } + #endif } public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) @@ -79,7 +74,13 @@ private static void ExecutePass(PassData passData, ref RenderingData renderingDa ProcessEffect(ref context); } #else + tmpRT1 = RenderTexture.GetTemporary(renderingData.cameraData.cameraTargetDescriptor); + tmpRT2 = RenderTexture.GetTemporary(renderingData.cameraData.cameraTargetDescriptor); + ProcessEffect(ref context); + + RenderTexture.ReleaseTemporary(tmpRT1); + RenderTexture.ReleaseTemporary(tmpRT2); #endif context.ExecuteCommandBuffer(cmd); @@ -140,8 +141,13 @@ internal class PassData public float scale; public int iterations; - public RTHandle tmpRT1; - public RTHandle tmpRT2; + public + #if UNITY_2022_1_OR_NEWER + RTHandle + #else + RenderTexture + #endif + tmpRT1, tmpRT2; } } }