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

[2d Lights] We're using a perspective camera, any way to get 2D lights to work properly?

Discussion in '2D Experimental Preview' started by laserDogRob, Mar 26, 2021.

  1. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Hi,

    We implemented 2D lights in 2020.3. They work great. Our game is topdown 2D, however we use a perspective camera to add some depth.

    Since updating to 2021.1, the lights appear in a small area in the centre of the screen, bleeding out to the edge. As soon as I change back to a orthographic camera they work correctly, but lose the lovely depth we've been working on.

    Obviously, we could stop using the 2D renderer and implement normal lights, but we've put in so much work already and 2D lights have been giving us the desired effect. They look awesome (in 2020.3 at least!).

    Thanks,

    (I think I posted this in the wrong form before, sorry)
     

    Attached Files:

  2. benandlilian

    benandlilian

    Joined:
    Aug 12, 2020
    Posts:
    1
    Light Bug.png I have the same problem... I hope someone found a solution.. :)
     
    Last edited: Mar 27, 2021
  3. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Fingers crossed this is a bug that will be fixed rather than a feature ie you have to use a orthographic camera :D
     
  4. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    As far as I know, 2D lights where never meant or designed to work with perspective cameras. (@Chris_Chu correct me if I am wrong). :cool:
    Unfortunately you will likely need to go with option B (use 3D lights). :(

    [EDIT] Yep. I stand corrected. Hopefully the 2D lights get patched!
     
    Last edited: Apr 6, 2021
  5. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Ugh, that's a real pain. The 2D lights do everything we need. 3D lights and sprites (that rhymes ) are such a hassle.

    As it currently works with a perspective camera in 2020.2.5f, I'm hoping there might be a "fix".

    If anyone from the team could comment, that would be amazing as I need to plan.

    Thanks!
     
    CheMBurN, NotaNaN and asrdoc_bwa like this.
  6. asrdoc_bwa

    asrdoc_bwa

    Joined:
    Nov 24, 2017
    Posts:
    1
    That's hilarious as one of Unity's own videos from Unite 2020 heavily featuring the 2D lights system, Tails of Iron, is using a perspective camera with 2D lights!


    I hope this is not the case, as the way they are working in 2020.3 is great.
     
  7. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    361
    I have the same problem. My lights don't work anymore since I upgraded and setting the camera to orthographic fixes it. But as others have said, I want to use a perspective camera. This worked before and is also in multiple official tutorials. This needs to be fixed. You can't expect everyone to use an orthographic camera for 2D games.
     
  8. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Hopefully it'll get fixed soon!
     
    NotaNaN likes this.
  9. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257

    Let me start by saying, lighting with perspective is supposed to work.

    There were a number of bugs that cropped up from changes made to the SRP core and Universal, that changed the behavior for our perspective lights. I thought I fixed most of the issues in 2021.1f1. Did either of you tried 2021.1f1? If so can you log a bug so I can look into fixing this?
     
  10. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Thanks so much for the reply. I'll download that version and have a test.
     
  11. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    361
    I just tried 2021.1f3 and my lights seem to be working again. Thank you!
     
    EvOne and NotaNaN like this.
  12. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Glad to hear it.
     
    NotaNaN likes this.
  13. flapierrelds

    flapierrelds

    Joined:
    Dec 16, 2012
    Posts:
    9
    Hello.

    We've just updated to Unity 2021.1.5f1 and 2D lights does work. However, ShadowCaster2D seems to be still limited to Orthographic camera. The Shadow texture is all wrong when using a Perspective camera. Is it possible to get a fix for this since we are using the ShadowCaster2D in our game?

    Thanks,
    Francis
     
  14. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Sorry I missed this when I made my fix. There is a fix for this incoming and I'll be looking at adding more test coverage so that this hopefully won't happen in the future.
     
  15. flapierrelds

    flapierrelds

    Joined:
    Dec 16, 2012
    Posts:
    9
    Great! We'll be waiting for the fix. Thank you for this nice feature.
     
  16. dvoronin

    dvoronin

    Joined:
    Oct 19, 2016
    Posts:
    16
    @Chris_Chu I updated Unity to 2021.1.5f1 and can confirm that 2D lights work now!

    However I have a new issue I can not explain.
    Please see the image attached.

    Basically: lights are mirrored by Y axis.
    So in the editor I setup light at Y = -6 and in game view it turns in Y=6.

    I made an image with examples. Second light is in Y=0 and it matches in both game view and editor.
    Same behavior for both orthographic & perspective cameras.

    UPDATE: the light position is correct in camera preview (smaill window in editor window when camera is selected).

    UPDATE #2: Enabling Post-Processing on camera fixed the issue, but that is weird.
     

    Attached Files:

    Last edited: May 5, 2021
  17. flapierrelds

    flapierrelds

    Joined:
    Dec 16, 2012
    Posts:
    9
    Hello. Any ETA when this fix will be released? We are getting really close to finish our Vertical Slice and we want to send it to some publishers. However, we cannot send the build until this is fixed since it breaks a gameplay feature in our game.

    Worst case, is this something that I can fix on my side. Is this exposed in the package code?

    Thanks
     
  18. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    pahe likes this.
  19. mgregoirelds

    mgregoirelds

    Joined:
    Feb 3, 2017
    Posts:
    22
    Hello Chris, I just downloaded the latest 2021.1 staging repo and manually added com.unity.render-pipelines.universal to our project. It seems like the issue with ShadowCaster2D is still there. Has the fix been pushed in 2021.1? I can't see anything related to this issue in the com.unity.render-pipelines.universal history. This bug is really problematic for us right now as it breaks the whole gameplay design of our level.
     
    Last edited: Jun 14, 2021
  20. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Just to add to this thread, the perspective issue I started this thread with, regarding 2D lights has been fixed, however the same issue still persists with ShadowCaster2D.

    Could we get an update from the unity team on this?

    Thanks :)
     
  21. flapierrelds

    flapierrelds

    Joined:
    Dec 16, 2012
    Posts:
    9
    Hello. Is there any progress on the Shadow Caster issue? This is preventing us from using this feature and create problems with a gameplay feature we have.

    Thanks.
     
    mgregoirelds likes this.
  22. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    It's getting kinda frustrating now :(
     
  23. flapierrelds

    flapierrelds

    Joined:
    Dec 16, 2012
    Posts:
    9
    Hello, I was waiting for the fix too and I finally fixed it myself. Here’s how:

    1) URP package needs to be embedded in your project so you can modify it. To do this, copy the package from the package folder into your project’s Packages folder.
    https://forum.unity.com/threads/modifying-a-package.680446/

    2) In the embedded package find the file LightingUtility.hlsl

    3) Modify the line 68
    Code (CSharp):
    1. output.ShadowUV = ComputeNormalizedDeviceCoordinate(output.PositionCS.xyz);
    by

    Code (CSharp):
    1. output.ShadowUV = ComputeNormalizedDeviceCoordinate(output.PositionCS.xyz / output.PositionCS.w);
    The division by .w will correctly render your shadow UV with a Perspective Camera. Otherwise, it will only work with an Orthographic Camera.
     

    Attached Files:

  24. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Thanks for this! Much appreciated!
     
  25. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    I just ran into the problem where 2D lights with a perspective camera stop working as well. The problem specifically occurred when upgrading 2021.1.13f1 to 2021.1.14f1; upgrading from 2021.1.13f1 directly to 2021.1.15f1 has the same result.

    What I'm seeing is that 2D lights in the scene view render correctly. Unfortunately, 2D lights in the game view, or in a player build do not renderer correctly.

    @Chris_Chu can you have a look at case 1353065? I filed a bug report detailing what I observed. Whatever change to URP's lighting from version 2021.1.13f1 (2D lights work fine) to 2021.1.14f1 is causing the problem to occur.
     
  26. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    I'm still seeing the same problem where 2D lights using a perspective camera stop working after upgrading 2021.1.13f1 directly to 2021.1.15f1, or directly to 2021.1.16f1.

    Something changed between 2021.1.13f1 and 2021.1.14f1 that affected 2D lighting when using perspective cameras.

    @Chris_Chu can you help track down this bug? If not, do you know of someone that would be able to work on this issue (detailed in cases 1353065 and 1354732).
     
  27. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Sorry, I must have missed seeing this thread earlier. The shadow caster in perspective mode was fixed in 2021.2 but had not been backported to 2021.1. It is now backported so it should be out when the next version of URP is released with the editor.

    As @TheSlap mentioned it needed a divide by w. A while back URP core API's changed which is what caused this breakage.

    We are improving our automated test coverage to make sure we can catch things like this in the future.

    I'm not sure why perspective lighting would be currently broken. I will check out what's going on with this when I get your bugs.
     
    Satobi46 likes this.
  28. mmmathias

    mmmathias

    Joined:
    Oct 17, 2017
    Posts:
    2
    Any updates on this?

    Having the sample problem here on Unity 2021.1.16f1. With perspective camera all lights look very funky, both in scene and in game view. Depending on camera position/rotation everything changes. But when I make my camera orthographic everything looks dandy in game view. And in scene view all looks fine when I click the 2D icon.
     
    JimmyKadesch likes this.
  29. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    I'm sticking on 2021.1.11f for now. Updating past that breaks the 2D lights system. We're close to launch on steam and consoles... Sucks really. Maybe we'll add shadows in a future update
     
    NotaNaN likes this.
  30. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    I received a reply to one of my bugs (case #1354732) on the issue of 2D lighting being broken when used with perspective cameras. The response was simply that is was a known issue: 1315645.

    Just upgraded to 2021.1.18f1 to see if it's been fixed, and it hasn't.
     
    JimmyKadesch likes this.
  31. JimmyKadesch

    JimmyKadesch

    Joined:
    Nov 22, 2019
    Posts:
    7
    kayroice likes this.
  32. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    @Chris_Chu
    Was forced to update to match nintendo switch software version and now Um running 2021.1.1.17f1 and its not working with perspective... All light are all over the place :S
    Any news on a updates coming?
    Cheers
     
    kayroice, JimmyKadesch and NotaNaN like this.
  33. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    I've come back to this thread to say the exact same thing. Had to update to 2021.1.19f1. Lights are all over the place.

    I don't think I need to specify more, but can if needed.

    I would absolutely love some good news about this as I'm completely screwed as it stands. We need to push a build out on switch for the publisher ASAP.

    Thanks
     
    kayroice and NotaNaN like this.
  34. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    And to add to this, have the shadow casters been looked at at all? Last time I tried to use them they still had the GetComponent in the update method and performance dropped below playable rates.
     
  35. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    I can see that it's stated as fixed in 2021.2, however it would be wonderful to see it back ported to 2021.1.x

    As 2021.2.x is still in preview, I'm a little reluctant to use it for a game we plan to ship in a month or so
     
    kayroice likes this.
  36. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    51
    The bug report for this issue, 1315645, can't be voted on since there's a fix (2021.2.0a10), but you can comment on the issue. Not sure if that results in increased visibility, but it's worth trying. I just commented asking for a fix in 2021.1.x, more voices won't hurt.

    @Chris_Chu do you happen to know if there's an ETA for backporting the 2D perspective lighting fix from 2021.2.0a10 to 2021.1.x?
     
    NotaNaN and laserDogRob like this.
  37. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    I will personally send a case of beer (or soft drink of your choice) to the person/team that back ports this to 2021.1.x
     
    JimmyKadesch, NotaNaN and kayroice like this.
  38. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    I need to do some other backports sometime this week. I'll take a look.
     
  39. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Do you like beer? ;)
     
    kayroice and NotaNaN like this.
  40. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    I also have to port to switch... If you update, pls Tag me and let me know how it went.
    Becuase; if you update, it might not work with the NDI Interface/Switch Version. Right?
    As far as I can tell, the Unity version and the Switch Version need to match?
     
  41. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    Thanks for looking into it!
     
    kayroice and JimmyKadesch like this.
  42. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    Thanks for looking into this, it means a lot. If we could have an update, that'd be great.
     
    JimmyKadesch and kayroice like this.
  43. JimmyKadesch

    JimmyKadesch

    Joined:
    Nov 22, 2019
    Posts:
    7
  44. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    ... Please ;(
     
  45. Skar_Universe

    Skar_Universe

    Joined:
    Sep 26, 2016
    Posts:
    5
    2d lights still broken with perspective view on 2021.1.22f1. Reading this thread makes me think I'll have to wait for 2021.2 at this pace. Please fix this!
     
    mGMM, BinarySouls and kayroice like this.
  46. laserDogRob

    laserDogRob

    Joined:
    Jun 20, 2018
    Posts:
    39
    kayroice likes this.
  47. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264
    Why did Unity get rid of this for later updates? It used to work.. I see that someone made a bugreport and it sais "this is just the way it is with perspectiv camera"


    [URP] [2D] [2D Lights] Sprite Light 2D will not illuminate sprites after reloading scene or entering Play Mode

    If the user positions a Sprite Light 2D in the illuminating range of a Sprite object, initially the user will see the sprite illuminated as expected. Upon entering Play Mode or reloading the scene, the Sprite Light 2D will no longer illuminate nearby sprites.

    Please see attached video capture for demonstration.

    Steps to reproduce:
    - Create a 2D new project with Unity 2019.3b+, configuring it for use with URP
    - Create a new scene
    - Add a 2D Sprite object to the scene
    - Add a Sprite Light 2D to the scene and position it within range of the sprite
    - Observe the sprite appears illuminated
    - Press the Play button to enter Play Mode
    - Observe the sprite is no longer lit as expected


    1. RESOLUTION NOTE:

      This is because you are using a perspective camera. The 2D lights are designed for orthographic cameras only, so weird artifacts may appear if you use them with a perspective camera. We may choose to properly support perspective cameras in the future, but for now we'll resolve this case as By Design.
     
    NotaNaN likes this.