Search Unity

Bug 2D shadow caster not working correctly...?

Discussion in '2D' started by Rechronicle, Apr 17, 2022.

  1. Rechronicle

    Rechronicle

    Joined:
    Dec 14, 2017
    Posts:
    32
    The shadow caster 2D only works on the highest light order. It just doesn't cast any shadow from other light sources in the scene at all. Any workaround to this?
    vlcsnap-2022-04-17-21h12m24s653.jpg
     
  2. MX-Pain

    MX-Pain

    Joined:
    Sep 27, 2020
    Posts:
    49
  3. Rechronicle

    Rechronicle

    Joined:
    Dec 14, 2017
    Posts:
    32
    got it, thanks for clarifying!
    I thought this will be fixed with the new 2021 LTS, but it is not.
    There is also a prefab override bug, going to wait for some patches then until it's fixed.
     
  4. MaxwellTan

    MaxwellTan

    Unity Technologies

    Joined:
    Mar 3, 2022
    Posts:
    75
    Hi Rechronicle, MX-Pain, thanks for the info, cool game you are making. I wondering if there any reproduce step that I can follow?
     
  5. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Hi, can you clarify what you mean by this?

    Shadows are rendered when
    a) Shadows are enabled on the Light2D
    b) Target Sorting Layers are the same for Light2D and Shadow Caster 2D

    If the bug is sometime else entirely, please report it using these steps. Thanks.
     
  6. Rechronicle

    Rechronicle

    Joined:
    Dec 14, 2017
    Posts:
    32
    Hi, this is the GIF to show it more clearly. Both Light2D settings are the same.
    No matter how many Light2D I added on the scene, the ShadowCaster2D only works from 1 light source.
    Unity 2021.3.0f1
    Animation .gif
     
  7. MaxwellTan

    MaxwellTan

    Unity Technologies

    Joined:
    Mar 3, 2022
    Posts:
    75
    Hi Rechronicle, thanks for the info. I manage to reproduce this issue and will be following up this issue.
     
    Rechronicle likes this.
  8. Ellbell

    Ellbell

    Joined:
    Jun 25, 2019
    Posts:
    5
    I found a solution. Edit ShadowCaster2D.cs at line 121 to always return true. This fixed the issue for me!
     
    GabrielWink likes this.
  9. GabrielWink

    GabrielWink

    Joined:
    Jun 30, 2018
    Posts:
    6
    Hello!
    I ran into this bug also and it was quite frustrating, so I did some experiments before submitting a bug report.
    If it can help to solve it, here is a video of the differents parts of the issue: https://drive.google.com/file/d/1MyOyrcPdU9LLvnuECFJAU0qXy3egvUQ9/view

    As shown in the video, several strange things happen around this bug:
    - If I move the second light closer to the shadow caster, the bug stops as soon as the lamp touches the caster.
    - If I zoom in enough in the scene, the bug disappears as soon as the secondary lamp is not visible anymore.
    - If I change the Light Order, the bug disappears as soon as the order of the second light is lower than the order of the first.
    - If I add another shadow caster on the second lamp, the bug disappears.

    This bug happens with Unity 2021.3.3f1 (Universal RP 12.1.6).
    I tried to reproduce this bug in the Unity 2022.1.1f1 version (Universal RP 13.1.8), and it seemed to be fixed (with the same conditions). But I finally managed to reproduce it, by putting a second shadow caster near the second light, and when the two lights are not on the same Blend Style.

    The solution proposed by @Ellbell is working, but I guess it's not good for performances. And speaking about performances... There seems to be some serious memory leaks in the shadow system, because as I deactivate/reactive shadow casters in my game, the performances are getting worse and worse, even with just one light. And as soon as I disable shadows from this light, everything becomes smooth again.
    According to the profiler, the problem seems to happen here:
    upload_2022-5-26_15-28-29.png

    Anyway, because of the bug and performance issues, the 2D shadows are currently impossible to use in a game imo, so I switched to the Smart lighting 2D from the asset store. But I hope the URP system will be usable again in the future :)
     
  10. PharmacyBrain

    PharmacyBrain

    Joined:
    Sep 8, 2020
    Posts:
    6
    Correction. It works on the light with the highest Light Order with shadows turned on and any lights within the Outer Radius of the light with the highest Light Order with shadows turned on. As a result I created a simple workaround for now.

    I am using 2021.3.3f1 and this is still an issue.

    1. Create a Light 2D
      1. Place the light in the center of the scene
      2. Set the Light Order to 999
      3. Increase the light's Outer Radius so it covers your entire scene
      4. Set its Intensity to 0
      5. Enable shadows and set Strength to 1
    2. Place your "real" lights in the scene using any Light Order < 999; typical numbers like 0, 1, 2, 3... use a "normal" radius, intensity, and so forth.
    3. Viola you have working shadows with as many lights as you want.

    However, I have no idea how this impacts performance. I have not measured, so don't beat me up. On my laptop I am not noticing any difference for all that is worth (not much I am sure).
     
    Last edited: May 30, 2022
    BHKeWin, Glazic, Weaver and 2 others like this.
  11. MaxwellTan

    MaxwellTan

    Unity Technologies

    Joined:
    Mar 3, 2022
    Posts:
    75
  12. ecoude

    ecoude

    Joined:
    Aug 15, 2019
    Posts:
    9
    Issue is still happening in 2021.3.12f1 (URP 12.1.7). Can't seem to edit the script personally. When I save it just rewrites what was initially there. Also, is line 121 to return of the IsLit() function?
     
  13. Quasimodem

    Quasimodem

    Joined:
    May 21, 2013
    Posts:
    53
    @PharmacyBrain You are the king of workarounds! I have been working with Unity since May 2022 to get this issue resolved. I have had multiple calls with their developer relations team and have watched numerous bug reports get kicked around, rejected, re-implemented and now... finally released (!!10 months later!!), only to my dismay, not address the issue even remotely.

    My sincere thanks for posting this workaround. It makes me cringe to think I might actually have to ship something like this, but Unity has really backed us all into a corner here with their rushed code and inability to release real fixes.
     
    PharmacyBrain and keithjones like this.
  14. Torren1292

    Torren1292

    Joined:
    Sep 29, 2022
    Posts:
    105
    Thank you for this workaround! It works brilliantly (light pun intended), and I, too, have not noticed any performance degredation.
     
    PharmacyBrain likes this.
  15. Drivinmecoco

    Drivinmecoco

    Joined:
    Dec 4, 2023
    Posts:
    1
    upload_2024-4-5_20-56-50.png
    Somehow the light is managing to kinda go past the shadow caster. This only happens at certain positions and angles
     

    Attached Files:

  16. Pierre-Marie

    Pierre-Marie

    Joined:
    Aug 3, 2015
    Posts:
    52
    Yeap I still have the problem, it's seen to be related to shadow caster attached to transform wich the scale are changed.

    I have made a simple scene from scratch:

    upload_2024-4-19_9-26-38.png

    By changind the scale of inner shadow caster :
    upload_2024-4-19_9-27-4.png

    I can make the shadow bug depending of the position of the light if the light is very close :

    upload_2024-4-19_9-27-59.png

    upload_2024-4-19_9-28-28.png

    @Drivinmecoco , check if your wall used a special scale and if putting it to (1,1,1) change the bug.

    Thanks for you help.