Skip to content

Commit d61be1a

Browse files
unity-cchuEvergreen
authored andcommitted
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)
1 parent 2c24a7c commit d61be1a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowRendering.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ internal static class ShadowRendering
2727

2828
private static RenderTargetHandle[] m_RenderTargets = null;
2929
private static RenderTargetIdentifier[] m_LightInputTextures = null;
30+
31+
private static readonly Color k_ColorNone = new Color(0, 0, 0, 0);
3032
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) };
3133
private static readonly ProfilingSampler[] m_ProfilingSamplerShadowColorsLookup = new ProfilingSampler[4] { m_ProfilingSamplerShadowsA, m_ProfilingSamplerShadowsB, m_ProfilingSamplerShadowsG, m_ProfilingSamplerShadowsR };
3234

35+
3336
public static uint maxTextureCount { get; private set; }
3437

3538
public static void InitializeBudget(uint maxTextureCount)
@@ -49,9 +52,7 @@ public static void InitializeBudget(uint maxTextureCount)
4952
}
5053

5154
if (m_LightInputTextures == null || m_LightInputTextures.Length != maxTextureCount)
52-
{
5355
m_LightInputTextures = new RenderTargetIdentifier[maxTextureCount];
54-
}
5556
}
5657

5758
private static Material[] CreateMaterials(Shader shader, int pass = 0)
@@ -135,15 +136,13 @@ public static bool PrerenderShadows(IRenderPass2D pass, RenderingData renderingD
135136
var textureIndex = shadowIndex / 4;
136137

137138
if (colorChannel == 0)
138-
ShadowRendering.CreateShadowRenderTexture(pass, renderingData, cmdBuffer, textureIndex);
139+
CreateShadowRenderTexture(pass, renderingData, cmdBuffer, textureIndex);
139140

140141
bool hadShadowsToRender = RenderShadows(pass, renderingData, cmdBuffer, layerToRender, light, shadowIntensity, m_RenderTargets[textureIndex].Identifier(), colorChannel);
141142

142143
// Render the shadows for this light
143-
if (RenderShadows(pass, renderingData, cmdBuffer, layerToRender, light, shadowIntensity, m_RenderTargets[textureIndex].Identifier(), colorChannel))
144+
if (hadShadowsToRender)
144145
m_LightInputTextures[textureIndex] = m_RenderTargets[textureIndex].Identifier();
145-
else
146-
m_LightInputTextures[textureIndex] = Texture2D.blackTexture;
147146

148147
return hadShadowsToRender;
149148
}
@@ -161,6 +160,7 @@ public static void SetGlobalShadowTexture(CommandBuffer cmdBuffer, Light2D light
161160

162161
public static void DisableGlobalShadowTexture(CommandBuffer cmdBuffer)
163162
{
163+
cmdBuffer.SetGlobalColor(k_ShadowColorMaskID, k_ColorNone);
164164
cmdBuffer.SetGlobalFloat(k_ShadowIntensityID, 1);
165165
cmdBuffer.SetGlobalFloat(k_ShadowVolumeIntensityID, 1);
166166
}

0 commit comments

Comments
 (0)