Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

[Unity2021.2.6] 2D Shadow RenderBuffer Clear Problems

Discussion in '2D Experimental Preview' started by ergexh, Dec 24, 2021.

  1. ergexh

    ergexh

    Joined:
    Sep 10, 2020
    Posts:
    3
    Not native speaker. Hope my expression would be clear. I just found a problem in 2D shadow rendering in Unity 2021.2.6. Here's a recording video.

    There are 2 light2D in this scene. They share the same sorting layer. The center one's light order is 1 and the upper-right one's order is 0. At start I just left the center light on and nothing wrong. When I enabled the upper-right light, something wrong happened. It seemed like the buffer rendering shadow can't be cleared correctly. If I drag the upper-right light closely to let the ShadowCaster2D's boundshpere meet lit condition, this bug vanished. Perhaps this bug only happens when there is a Light2D outside of the ShadowCaster2D's boundshpere. (Shadow is short because I modified the original code and reset the shadow radius.)



    I tried to fix this and it works. Additionally calling ClearRenderTarget in ReleaseShadowRenderTexture function in ShadowRendering.cs.

    Code (CSharp):
    1.         public static void ReleaseShadowRenderTexture(CommandBuffer cmdBuffer, int shadowIndex)
    2.         {
    3.             var colorChannel = shadowIndex % 4;
    4.             var textureIndex = shadowIndex / 4;
    5.  
    6.             if (colorChannel == 0)
    7.             {
    8.                 //Custom modification
    9.                 cmdBuffer.SetRenderTarget(m_RenderTargets[shadowIndex].id);
    10.                 cmdBuffer.ClearRenderTarget(true, true, Color.clear);
    11.                 //Original Code
    12.                 cmdBuffer.ReleaseTemporaryRT(m_RenderTargets[textureIndex].id);
    13.             }
    14.         }
    Simple fix. I'm actually quite greenhand to unity. Don't know if this is efficient enough. Hope unity official will fix this.