Search Issue Tracker
Active
Votes
0
Found in
2021.2
2021.2.1f1
2022.1
2022.2
Issue ID
1385216
Regression
No
[URP][2D] No shadows are cast from Point Light 2D when Global Light 2D is present
How to reproduce:
1. Open the attached project "lightRepro"
2. Open the scene "Game" (Assets/_Project/Scenes/Game.unity)
3. In the Scene view, observe that no shadows are visible
4. In the Hierarchy window, select the GameObject "Global Light 2D"
5. In the Inspector window, disable and re-enable the Light 2D component
6. Under "Light Type", change it to "Freeform" and back to "Global"
7. Inspect the Scene view
Expected result: No shadows are visible
Actual result: Shadows are visible
Reproducible with: 12.1.4 (2021.2.12f1), 13.1.5 (2022.1.0b8), 14.0.0 (2022.2.0a5)
Could not test with: 2019.4.36f1, 2020.3.30f1 (Experimental Light 2D)
Note: After following the steps, entering Play mode makes the shadows disappear again
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Android] [Particle System] "ParticleSystem.GeometryJob" sometimes takes up to ~20 ms in the worker thread when initializing 5 Particle Systems
- Can't change OpenXR settings when switching Build Profiles
- L(a,b) expression in float fields has erratic behaviour when ordering due to using instanceID as an index
- InvalidOperationException is thrown when switching to a custom Debug Draw Mode in Scene View
- [Android][Vulkan] Skybox and Environment effects flicker in the Player when using the Vulkan Graphics API
bgsulz
Feb 23, 2022 15:21
Thank you for working on this bug. I appreciate it very much! Since this upload, I managed to deduce a little more about it.
The Global Light 2D retains some of its settings from the previous light mode. That is, if you switch a Freeform Light 2D to a Global Light 2D, it retains some behavior from the Freeform Light 2D Mode.
From a blank URP/2D project, replicate like so:
- Set up an object with a Shadow Caster 2D component (and a Sprite-Lit background so you can see the shadows.)
- Create a Spot Light 2D, turn on Shadows, and observe that shadows are cast.
- Set the blend mode of the Spot Light 2D to Alpha Blend. Create a Global Light 2D and set the blend mode to Alpha Blend as well.
- Observe that shadows still behave as expected.
- Change the Global Light 2D to a Freeform Light 2D. Turn on Shadows. Change it back to a Global Light 2D.
- Observe that moving the Global Light 2D near the Shadow Caster 2D affects whether shadows are cast from the Spot Light 2D.
- Enter Play Mode. Observe that moving the Global Light 2D near the Shadow Caster 2D produces bizarre shadows.
I believe this is occurring because you do not properly update the bounding sphere for a Global Light 2D.
For Unity 2021 / URP 12:
(A) The switch statement in UpdateMesh() has no branch for Global light type. [Light2D.cs, line 340.]
As a result, m_localBounds is never updated when changing Light Type back to a Global Light 2D.
(B) Therefore, boundingSphere is never updated, because you return out of LateUpdate() if m_lightType is Global before it has a chance to call UpdateBoundingSphere(). [Light2D.cs, line 414.]
The several UpdateMesh() calls in Light2DEditor.cs do not update the bounding sphere because of point A.
The bounding sphere is never updated anywhere else because of point B. This LateUpdate() is the only place UpdateBoundingSphere() is called.
The boundingSphere property is critically important. You use it for shadow casting, culling, and so on.
Unity does not let me edit your work because it is part of a package, but I think you could start by revising UpdateMesh() to properly deal with the Global m_lightType.
Thank you again for your help. Please let me know if you have any questions.