- Home /
URP 2D lights not working as expected
Hi,
I am facing a weird issue with 2D lights. Lights are not correctly applied. And another issue is: even if I dont apply light to a layer, all layers are still lit.
Please, see below screenshots. Its a sample scene with only 3 sprites each in different sorting layers in sequence (Background, Middleground, Default). Scene has only one Global Light. When I set target sorting layers to none, light gets applied to all layers. Only when I disable the light from inspector all sprites turn black. Ideally, none target sorting layers should also turn my scene black. Another issue is: when I set specific layer, it doesnt apply to that particular layer. This is just an example of Global Light. Point and Parametric light behaves the same way.
I have also put all sprites in different z position to be sure.
URP Version: 8.2.0
Unity Version: 2020.1.2f1
Material Used for all sprites: Universal Render Pipeline/2d/Sprite-Lit-Default
Any help would be appreciated.
I also ran into this issue. As of 11/2/2021, none of the below answers solve the issue.
I asked about it on Game Dev Stack Exchange, as well as in Unity dev discord. No answer yet. For reference, my write up is at https://gamedev.stackexchange.com/questions/197676/lights-do-not-fully-respect-sortinglayers-in-universal-render-pipeline
Answer by justincredibleg · Nov 02, 2020 at 03:49 PM
Are you sure you're using the URP/2d/Sprite shader on all of the actual sprite objects? Within your sprite renderer are you setting the sorting layer there? The Layer up at the top of the editor isn't what you're targeting with the light.
Is there a reason you're using 2020 instead of 2019.4? Unless there is a specific feature you need in 2020 I'd recommend using a LTS version of 2019.4.
Thanks for reply. I am certain that I am using correct sorting layers. Not layers. Please, see below screenshot of background layer sprite. That screenshot also shows the material and shader.
While playing around this, I also found that if I add another Parametric light just sake of keeping it. Everything started working. So, it's not like URP and lighting are not working at all.
I am not looking for any specific feature in 2020. But, since I just started out project and 2020 will likely be LTS by next year spring, I thought let's start with latest. I think my project will go beyond 2021 December for sure.
Before I hit this snag, I didnt have any issues. $$anonymous$$oreover, I am not using any major preview version packages to be on safer side. But, I will certainly keep your suggestion in $$anonymous$$d and decided sooner.
Answer by SimplyNew · Nov 21, 2020 at 01:41 AM
Update:
I tried with different URP versions and looks like this works fine till 7.3.1. Post 7.3.1 all versions have this issue.
Do anyone else has similar issue? I have reverted URP version to 7.3.1 for now.
Answer by MilkIsTheBest · Jan 30, 2021 at 11:04 AM
Think I got a solution. What I did is to keep the light with the target sorting layer, add a global light, set the new global lights color too black, and change target sorting layer of the new global light to all. Hope it works for all of you.
Answer by FireFoundry01 · Apr 26, 2021 at 02:36 AM
Your answer
Follow this Question
Related Questions
Sorting layer ignores 2d lights from the 2d renderer 0 Answers
Extrange Behaviour with 2D Lights in Universal RP 0 Answers
Universal Render Pipeline use 2D and 3D lights at the same time 0 Answers
Shadow bug 0 Answers
How to only show sprite with 2D light? 0 Answers