Skip to content

Commit

Permalink
Fixes multiply rendered shadows and missing shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
unity-cchu authored and Evergreen committed Jan 10, 2024
1 parent 2c24a7c commit d61be1a
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit d61be1a

Please sign in to comment.