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
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Are 2D Lights compatible with a Perspective Camera?

Discussion in '2D Experimental Preview' started by Igotlazy, Jan 1, 2020.

  1. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    67
    I’ve been messing around with the new lights and while they work for the most part, they seem to glitch out horribly on large sprites and when the Camera rotates on the X and Y axis. This is at least, when the Camera is set to Perspective. On Orthographic is seems fine. Are the 2D Lights compatible with a perspective camera? Is there anything I can do to get rid of the issues I listed?
     
    dvoronin and Klavakrapstis like this.
  2. dvoronin

    dvoronin

    Joined:
    Oct 19, 2016
    Posts:
    16
    I'm having the same issue. 2d lights seem not to work at all with perspective camera.
     
  3. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    I know replied to you in another thread as well, but just for completeness.

    They should work. If they don't something is wrong. If anyone is having issues with this please submit a bug report if you can.
     
  4. postmortembg

    postmortembg

    Joined:
    May 23, 2020
    Posts:
    3
    Can confirm - in 2021.1.15 they don't work at all with perspective camera - the only working is global 2d light
     
  5. Karl_Bot

    Karl_Bot

    Joined:
    Jul 9, 2013
    Posts:
    6
    NotaNaN likes this.
  6. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    I'm at the unfortunate point now where I might need to strip out the 2D lights and rework everything with 3D lights. I have 3 weeks to port the game to switch (and actually finish the game) and I'm pulling my hair out.
     
    NotaNaN likes this.
  7. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Hi, I've backported the fix to the lighting issue with perspective camera. Apologies for the delay and I'll keep you updated when the package is published.
     
    RuneShiStorm, NotaNaN and laserDogRob like this.
  8. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Omg, that's amazing. Thanks so much. I've been stressing about this so much. Just got into the office this morning with a plan to rewrite the whole lighting of the game with 2 weeks left to launch. THANK YOU
     
  9. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    I can't guarantee the package can be published in time. The fix is simple enough that you may want to change your package locally. Please take note, doing so will cause the package to not automatically update since it's a local copy.

    Here are the steps if you plan to proceed:
    Navigate to ProjectName/Library/PackageCache/com.unity.render-pipelines.core@11.0.0
    Copy this folder to ProjectName/Packages folder
    Open ProjectName/Packages/com.unity.render-pipelines.universal@11.0.0/Shaders/2D/Sprite-Lit-Default.shader to edit

    Change line 89
    Code (CSharp):
    1. o.lightingUV = half2(ComputeScreenPos(o.positionCS / o.positionCS.w).xy);
    Let me know if this works for you or if you need more help.
     
    NotaNaN likes this.
  10. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Ah, thanks for this. I tried to get the package locally before but didn't manage it. I'll give this a go.
     
  11. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    That seems to work great, thanks. The editor seems a lot slower, a lot of slowdowns in gameplay, but that's most likely a completely separate issue. (Builds run fine)
     
  12. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    FYI - I installed the latest version (2021.1.22f1) and (for both of our workstations) playing the game in the editor was unplayable. Rolled back to 2021.1.20f1 and it's working fine again.

    Not sure this is a known bug, just throwing it out there. We're totally up against it at the moment so no time to try get a simple repro to raise a bug report I'm afraid.
     
  13. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    @kennyy_, can you confirm that this fix will make it into a 2021.1.x release (or not)?
     
  14. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264

    is this still the way to fix the lights in perspective camera?
    My lights are all over the place in Unity 2021.1.17f1
     
  15. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Worked for me in 2021.1.19f1
     
    RuneShiStorm likes this.
  16. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    @laserDogRob Thanks for confirming the local fix!

    @kayroice Yes, I can confirm the fix will make it into the next packaged release 2021.1.24. Unfortunately, I cannot give you a release date.

    @RuneShiStorm Please be aware that this is a local only fix. I would still recommend removing the copied package and updating to the new release once it is out.
     
    RuneShiStorm and kayroice like this.
  17. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    any date when its out? - I see you cant give relase date yet. Thanks!
    I, like some other users are ready to launch game but can't due to the light -glitch :S
    thnkas!
     
    Last edited: Oct 7, 2021
  18. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    I just upgraded to 2021.1.24 and my 2D lights are still broken when using a perspective camera; this is using the URP-11.0.0 package.

    I didn't see a 2D lighting fix mentioned in the 2021.1.24 release notes (maybe I missed it?). @kennyy_ , do you happen to know if the fix missed the 2021.1.24 release, and if it's maybe scheduled for a later release?
     
  19. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    @kayroice It looks like the fix didn't make it to 2021.1.24 release. I will check the release schedule and update this thread once I find out more.
     
    Skar_Universe and kayroice like this.
  20. Skar_Universe

    Skar_Universe

    Joined:
    Sep 26, 2016
    Posts:
    5
    any update on this? hope the fix makes it in the next release.. really looking forward to starting lighting and LD with perspective cams.

    [EDIT] Sadly light's still seem broken on 2021.1.25f1.
     
    Last edited: Oct 15, 2021
    kayroice likes this.
  21. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    Skar_Universe likes this.
  22. Skar_Universe

    Skar_Universe

    Joined:
    Sep 26, 2016
    Posts:
    5
    Sad... is there a timeline on when 2021.2 will be out of BETA? any clue?
     
  23. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    It workes for me in 2021.2.0b14 - but sadly I need it to work in 2021.1.17f1 since thats the version Im porting to conosle.
     
  24. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    This worked now! I tried in the past but since you're not using . or 1. etc I just changed the line in the original folder. Im an idiot >_< So in case another dyslectic idiot like me sees this. Let me dummify it:

    1. Copy Folder (com.unity.render-pipelines.core@11.0.0) -> To -> ProjectName/Packages.
    - This Folder: com.unity.render-pipelines.core@11.0.0 is located in ProjectName/Library/PackageCache/com.unity.render-pipelines.core@11.0.0.

    2. Once you have copied com.unity.render-pipelines.core@11.0.0 to ProjectName/Packages, open a file called sprite-Lit-Default.shader.
    - Its now located in ProjectName/Packages/com.unity.render-pipelines.universal@11.0.0/Shaders/2D/Sprite-Lit-Default.shader

    And change line 89 to

    o.lightingUV = half2(ComputeScreenPos(o.positionCS / o.positionCS.w).xy);
     
    Last edited: Oct 24, 2021
  25. Skar_Universe

    Skar_Universe

    Joined:
    Sep 26, 2016
    Posts:
    5
    Thank you.. this does work indeed. Now I just need to make sure I delete this new folder I created once the fix is officially released right?
     
    RuneShiStorm likes this.
  26. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Hi all, the fix made it in 2021.1.27f1.
     
  27. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    Installed 2021.1.27f1 and confirmed that 2D lights are now working with perspective cameras. Thank you @kennyy_ for pushing that fix through the release pipeline.
     
  28. harusame-

    harusame-

    Joined:
    Nov 18, 2013
    Posts:
    11
    Hello,

    I've a similar problem with unity 2021.2.0f1, any plan to fix it ?
     
  29. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    It should be fixed in the latest 2021.2.

    When we make fixes we usually make them in the latest version and backport all the way back to a certain version. If it is not fixed in 2021.2 and is fixed 2021.1 then a mistake was made in backporting. Definitely let us know either in a bug report of the forums if this is the case.
     
  30. Geoffl

    Geoffl

    Joined:
    Nov 22, 2012
    Posts:
    6

    I'm seeing what sounds like a similar issue with perspective cameras: when using a perspective camera (even with no rotation) any x or y rotation on a sprite will cause the lighting to be in the wrong place. Works fine with orthographic cameras (see scene view), but perspective + x/y sprite rotation seems to cause problems (camera rotation does not).

    This is with Unity 2021.3.10f1 and URP 12.1.7. @Chris_Chu @kennyy_ Is this something you'd expect to be working or is this scenario unsupported?
     
  31. Geoffl

    Geoffl

    Joined:
    Nov 22, 2012
    Posts:
    6
    Correction: I saw the same behavior when rotating the camera by the same amount and with the sprite unrotated. I guess the issue is just lighting/shadows don't work with any kind of relative rotation.
     
  32. Geoffl

    Geoffl

    Joined:
    Nov 22, 2012
    Posts:
    6
    Jamez0r likes this.