From d61be1ab0ea6387b2e48f7af12be064d520b5f48 Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Wed, 10 Jan 2024 00:17:49 +0000 Subject: [PATCH] Fixes multiply rendered shadows and missing shadows Fixes two bugs: https://jira.unity3d.com/browse/D2D-4877 (UUM-59844) https://jira.unity3d.com/browse/D2D-4817 (UUM-1855) --- .../Runtime/2D/Shadows/ShadowRendering.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowRendering.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowRendering.cs index b5d7dcad4fd..45c851d22d3 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowRendering.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowRendering.cs @@ -27,9 +27,12 @@ internal static class ShadowRendering private static RenderTargetHandle[] m_RenderTargets = null; private static RenderTargetIdentifier[] m_LightInputTextures = null; + + private static readonly Color k_ColorNone = new Color(0, 0, 0, 0); private static readonly Color[] k_ColorLookup = new Color[4] { new Color(0, 0, 0, 1), new Color(0, 0, 1, 0), new Color(0, 1, 0, 0), new Color(1, 0, 0, 0) }; private static readonly ProfilingSampler[] m_ProfilingSamplerShadowColorsLookup = new ProfilingSampler[4] { m_ProfilingSamplerShadowsA, m_ProfilingSamplerShadowsB, m_ProfilingSamplerShadowsG, m_ProfilingSamplerShadowsR }; + public static uint maxTextureCount { get; private set; } public static void InitializeBudget(uint maxTextureCount) @@ -49,9 +52,7 @@ public static void InitializeBudget(uint maxTextureCount) } if (m_LightInputTextures == null || m_LightInputTextures.Length != maxTextureCount) - { m_LightInputTextures = new RenderTargetIdentifier[maxTextureCount]; - } } private static Material[] CreateMaterials(Shader shader, int pass = 0) @@ -135,15 +136,13 @@ public static bool PrerenderShadows(IRenderPass2D pass, RenderingData renderingD var textureIndex = shadowIndex / 4; if (colorChannel == 0) - ShadowRendering.CreateShadowRenderTexture(pass, renderingData, cmdBuffer, textureIndex); + CreateShadowRenderTexture(pass, renderingData, cmdBuffer, textureIndex); bool hadShadowsToRender = RenderShadows(pass, renderingData, cmdBuffer, layerToRender, light, shadowIntensity, m_RenderTargets[textureIndex].Identifier(), colorChannel); // Render the shadows for this light - if (RenderShadows(pass, renderingData, cmdBuffer, layerToRender, light, shadowIntensity, m_RenderTargets[textureIndex].Identifier(), colorChannel)) + if (hadShadowsToRender) m_LightInputTextures[textureIndex] = m_RenderTargets[textureIndex].Identifier(); - else - m_LightInputTextures[textureIndex] = Texture2D.blackTexture; return hadShadowsToRender; } @@ -161,6 +160,7 @@ public static void SetGlobalShadowTexture(CommandBuffer cmdBuffer, Light2D light public static void DisableGlobalShadowTexture(CommandBuffer cmdBuffer) { + cmdBuffer.SetGlobalColor(k_ShadowColorMaskID, k_ColorNone); cmdBuffer.SetGlobalFloat(k_ShadowIntensityID, 1); cmdBuffer.SetGlobalFloat(k_ShadowVolumeIntensityID, 1); }