Search Unity

  1. Want to see 2020.1b in action? Sign up for our Beta 2020.1 Overview Webinar on April 20th for a live presentation from our evangelists and a Q&A session with guests from R&D.
    Dismiss Notice
  2. Interested in giving us feedback? Join our online research interviews on a broad range of topics and share your insights with us.
    Dismiss Notice
  3. We're hosting a webinar for the new Input System where you'll be able to get in touch with the devs. Sign up now and share your questions with us in preparation for the session on April 15.
    Dismiss Notice

Unity Experimental 2D Lights and Shader Graph support in LWRP

Discussion in '2D Experimental Preview' started by rustum, May 24, 2019.

  1. pyroklasticgames

    pyroklasticgames

    Joined:
    Sep 8, 2019
    Posts:
    2
    Hi I'm pretty new to Unity, I love the way this feature handles but I'm not sure how to track down documentation on controlling the LWRP 2D lights through script? I'd like to alter my Global 2D lights [color] and [intensity] depending on the time of day inside my game. Can anyone direct me to scripting reference for something like that? Thanks for any help. example.png
     
  2. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    Bloom, the last time I tried was working fine. There are a lot of steps to get post processing set up, hopefully its just something you missed. However, if you find a set up that works in URP, that doesn't work with the 2D Renderer, please post what you did.
     
  3. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    At the moment, you'd have to use a Render Texture. This is a known issue and we will look into a solution, but I can't tell you what that will be.
     
  4. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    37
    I'm loving the new 2D lights and shadows but what is the recommended way to edit a dark level? Can this be set up to use the Scene View light toggle? It would be awesome to turn lighting off for editing.

    SceneLightToggle.PNG
     
  5. cecilcruxis

    cecilcruxis

    Joined:
    Sep 17, 2013
    Posts:
    98
    I second this. I am having to put in a temporary global light just t edit tile maps and stuff.
     
  6. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    The Light class is at UnityEngine.Experimental.Rendering.LWRP.Light2D
    https://docs.unity3d.com/Packages/c...gine.Experimental.Rendering.LWRP.Light2D.html
     
    pyroklasticgames likes this.
  7. PeanutSoupMcMuffin

    PeanutSoupMcMuffin

    Joined:
    Jun 6, 2017
    Posts:
    6
    Hey, it sounds like shadows have been implemented now, which is really cool! Would someone please be able to explain how I could use this in my project? My setup is pretty simple: I have a player with a point light, background tiles and wall tiles all using the sprite-lit-default material. I would like the wall tiles to create shadows, so that the light doesn't pass through them.

    I'm rather new to this, so please let me know if my question doesn't make sense, or belongs somewhere else. Thanks! :)
     
  8. pyroklasticgames

    pyroklasticgames

    Joined:
    Sep 8, 2019
    Posts:
    2
  9. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    Objects that are required to cast a shadow must have a ShadowCaster 2D script on the sprite you wish to have cast shadows. Additionally, any shadow casting lights must have their Shadow Intensity set to non-zero.

    Note: There is a bug right now where if you had a pre-existing 2D Renderer Data (created before shadows was released) you may have your scene disappear when adjusting the Shadow Intensity slider. For now, you will need to create a new 2D Renderer Data.
     
    PeanutSoupMcMuffin likes this.
  10. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    I'm working on this now.
     
    cparki77, BTStone and mahdi_jeddi like this.
  11. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    271
    Are you using TileMap for the ground area?
     
  12. Meepo0

    Meepo0

    Joined:
    Nov 24, 2017
    Posts:
    27
    Yes, I am using TileMap for the ground!
     
  13. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    62
    hi @Chris_Chu . I tried again and haven't been able to get it working. It must be something I am doing wrong so I will list my steps here - using Unity 2019.3.0b7.

    Create a fresh 2D project.

    Add package for URP (7.1.2) through the Package Manager.

    Create -> Rendering -> Universal Render Pipeline -> Pipeline Asset (Forward Renderer).

    Edit -> Project Settings -> Graphics -> assign the Pipeline Asset previously created.

    Create -> Rendering -> Universal Render Pipeline -> 2D Renderer (Experimental).

    Assign the 2D Renderer to the previously created Pipeline Asset.

    Add a 2D light to the scene.

    Edit -> Render Pipeline -> Universal Render Pipeline -> 2D Renderer -> Upgrade Scene to 2D Renderer.

    *** And great! My 2D light is working and everything looks fine up to here. ***

    Now I attempt to set up Post Processing.

    I add the package for Post Processing (2.1.7).

    I add the Component -> Rendering -> Post-process Layer to my main (and only) Camera.

    I create a New Post Processing Profile and add Bloom to it, checking the box for Intensity and setting it to something I should be able to see, such as 30.

    Now I have tried to add a Post Processing Volume to anything - the camera, an empty Game Object etc
    via Component -> Rendering -> Post-process Volume

    Nothing works. I have tried things on their own layer and also just on the default layer. I have tried checking Is Global or having it unchecked. I cannot get the Bloom to show at all with my single 2D light. Of note, I can reliably make Bloom work in a normal default 2D scene.

    The only things I have in my scene in this case are the camera, a sprite to test the bloom on, a background image and a single 2D point light.



    I'd love to get this working and figure I must be missing a piece of wisdom somewhere here. o_O
     
  14. PeanutSoupMcMuffin

    PeanutSoupMcMuffin

    Joined:
    Jun 6, 2017
    Posts:
    6
    Hi Chris,

    Thanks a bunch for the info! However, I've followed your steps, and I can't find the ShadowCaster2D script or the Shadow Intensity setting, which indicates to me I might have the wrong version or something. Universal RP in the Package Manager says up to date.

    I've tried redoing the lighting setup from scratch: making a new Pipeline Asset and 2D Renderer Data, setting up those in Project Settings, and doing Upgrade Scene to 2D Renderer. Still don't see either of the things you mentioned. Here's what my 2D Light component shows for settings:

    upload_2019-10-22_20-48-37.png

    Thanks again for the help.
     
  15. cecilcruxis

    cecilcruxis

    Joined:
    Sep 17, 2013
    Posts:
    98
    I was wondering if anyone knew how to add a light2d to a particle effect? Tried making a 2d point light earlier and bringing it into the particle effect, but no goes.
     
  16. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99

    If you have URP 7.1.2, you should try the integrated post-processing. You won't need the post-processing package.

    Instead, Add the component Volume to your camera and click new next to profile.

    You will now see an Add Override button. Click that and Select Post-processing->Bloom.

    Check threshold and intensity.

    You will also need to go to the Rendering section under your camera and check Post-processing.

    There are also other settings in the Universal Render Pipeline Asset under a Post-processing section. In addition in the asset, you can enable HDR for 2D lighting by going to the Quality section and checking HDR.
     
  17. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    You need to make sure you have version 7.1.2 from the package manager. Once you do that you will need to create a new 2D Renderer Data Asset. That should give you a different light inspector with a shadows slider.

    If you don't have 7.1.2, there should be a button at the bottom right of the package manager that says Update to 7.1.2. If there isn't, go to the package manager and on the left side, find Universal RP in the list of packages. Open the fold out and try to manually install it.
     
  18. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    Currently, there isn't a way to emit 2d lights from a particle effect. We are exploring how to best fix this.
     
  19. PeanutSoupMcMuffin

    PeanutSoupMcMuffin

    Joined:
    Jun 6, 2017
    Posts:
    6
    Yeah, it won't let me update it. Do I need a more recent version of Unity? This project is on 2019.3.0b1. Thanks!
     
  20. PeanutSoupMcMuffin

    PeanutSoupMcMuffin

    Joined:
    Jun 6, 2017
    Posts:
    6
    Got it solved. I didn't see the drop-down menu of versions that you mentioned at first. :)
     
  21. Bilion

    Bilion

    Joined:
    Oct 13, 2019
    Posts:
    27
    How do I create a 2d shadow?
     
  22. PeanutSoupMcMuffin

    PeanutSoupMcMuffin

    Joined:
    Jun 6, 2017
    Posts:
    6
    Hey everyone, I'm really enjoying the 2D shadows and lighting and have it mostly working, however I can't find a way around this issue. The ShadowCaster2D has a Shape editor which I would like to use in my procedural generation algorithm to change the shape of the shadows different objects cast. However, there seems to be no way to edit the shape in code. Is there any support for this that I am unaware of or will there be in the future?

    Thanks.
    upload_2019-10-27_21-17-7.png
     
  23. PeanutSoupMcMuffin

    PeanutSoupMcMuffin

    Joined:
    Jun 6, 2017
    Posts:
    6
    The steps for how to do so have been mostly explained earlier in this thread, but as a general summary:
    1. Setup your scene to use the LWRP (make sure you have Universal RP version 7.1.2).
    2. Create a GameObject with a Light2D component. Set ShadowIntensity to greater than 0.
    3. Create a second GameObject with a ShadowCaster2D component.
    4. Move the two objects close enough for the light to hit the second GameObject.

    You should now see the second GameObject will cast shadows based on the light source of the first GameObject. Feel free to reply again if you are confused with any of these steps.
     
  24. dquek

    dquek

    Unity Technologies

    Joined:
    Apr 17, 2018
    Posts:
    57
    Bilion likes this.
  25. Wonka45

    Wonka45

    Joined:
    Aug 24, 2014
    Posts:
    13
    @dquek
    What would be the timeframe for normal maps working with sprite atlases?
     
    Last edited: Nov 1, 2019
  26. Bilion

    Bilion

    Joined:
    Oct 13, 2019
    Posts:
    27
  27. kvam

    kvam

    Joined:
    Sep 28, 2019
    Posts:
    9
    I have the problem of this message showing up when i drop the Universal Render Pipeline 2D-asset into my settings. Any ideas of how to fix this?

    Code (CSharp):
    1. Dimensions of color surface does not match dimensions of depth surface
    2. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    Also, when I follow the steps above with the post processing volume, nothing seems to happen (no grain for instance). Could there be a problem that I am using Cinemachine?
     
  28. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    271
    Is it possible for us to have a repro project?
    Cinemachine should have nothing to do with this. What documentation were you following? If something is not clear, we can ask our tech writers to fix it.
     
  29. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    271
    Currently we still don't have an ETA for this. But rest assured, we will get that sorted out before we label the 2D Renderer as production ready.
     
  30. Wonka45

    Wonka45

    Joined:
    Aug 24, 2014
    Posts:
    13
    + @Chris_Chu , @dquek
    What about Target Sorting Layers available in code?
     
    Last edited: Nov 7, 2019
  31. kvam

    kvam

    Joined:
    Sep 28, 2019
    Posts:
    9
    Well, this is my first project (and a prototype at that, not anything for production), so maybe the easiest thing is for me to share my project with one of you? Definitely not sure how to reproduce outside my current project, but I can recreate it easily in this one. I could also duplicate the project and just remove all the game objects and see if it still happens.

    Regarding post-processing, I followed the steps outlined by Chris above:

    "
    If you have URP 7.1.2, you should try the integrated post-processing. You won't need the post-processing package.

    Instead, Add the component Volume to your camera and click new next to profile.

    You will now see an Add Override button. Click that and Select Post-processing->Bloom.

    Check threshold and intensity.

    You will also need to go to the Rendering section under your camera and check Post-processing.

    There are also other settings in the Universal Render Pipeline Asset under a Post-processing section. In addition in the asset, you can enable HDR for 2D lighting by going to the Quality section and checking HDR.
    "

    EDIT: I followed the steps above, with the Post Processing Volume etc., and nothing happened. I then tried adding it as "Cinemachine Post-Processing" and nothing happened. My "idea" as a beginner was to think that because cinemachine "takes over" a lot of the control, it might also affect this, and that's why I asked.

    EDIT2: Regarding things that are not clear, i guess the only thing i could think of is that beginners might have a hard time understanding what you will be "losing" by going over to the LWRP/URP 2D render pipeline. For instance, you gain the amazing lighting effect on sprites, but you lose lit particles.

    EDIT3: Regarding post processing. I'm an idiot. I added a "post processing volume" and not a "volume". Works now. Still have the color issue, and not able to reproduce.
     
    Last edited: Nov 4, 2019
  32. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    Actually I'm glad you posted this. I think this is an easy mistake to make, I suspect other people will have have the same issue.
     
    kvam likes this.
  33. kvam

    kvam

    Joined:
    Sep 28, 2019
    Posts:
    9
    Do you have an email or something where I can share the project with you?
     
  34. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,620
    If you can make a small enough repro project, you can just send a bug report with the project attached. If you have to upload a larger project, send a bug report and mention that you need an upload link.
     
  35. ManuelMeisen

    ManuelMeisen

    Joined:
    Sep 14, 2019
    Posts:
    5
    I integrated the 2d shadows now and they are very cool.
    They do break batching very heavily though. Just one shadow caster on my main character affecting 2 layers adds around 200 batches in my project.

    I also tried putting them on my wall tiles (one caster per tile) and noticed shadowcasters that are completely off screen still add those draw calls, completely breaking performance. 1000 Shadow casters added up to 100.000 batches,
    and 200ms for the render pipeline script. As far as I know its not possible to add a shadow caster to a tilemap?

    Did I do something horribly wrong or is that something you are still planning to improve?
     
    BinaryByron and EvOne like this.
  36. valyth

    valyth

    Joined:
    Oct 12, 2019
    Posts:
    3
    When I try to update from 7.1.1 to 7.1.2 I get the following error.

    Unable to add package [com.unity.render-pipelines.lightweight@7.1.2]:
    One of more dependencies could not be added to the local file system:
    com.unity.render-pipelines.core: EBUSY: resource busy or locked, open 'D:\Projects\ConceptualRPG\Library\PackageCache\.tmp21732NAY8ESQbtqMG\copy\Editor\EditorUtils.cs'
    com.unity.shadergraph: EBUSY: resource busy or locked, open 'D:\Projects\ConceptualRPG\Library\PackageCache\.tmp21732BQjkYJgW2Ks5\copy\Editor\CodeGen\ShaderGeneratorNames.cs'

    Does anyone have any idea how to resolve this?

    I tried uninstalling and reinstalling but... no dice. Thankfully I had, of course, backed my project up, but as it stands I don't see a good way to update.
     
    Last edited: Nov 10, 2019
  37. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    936
    I'm just wondering if the light performance (particularly 2D point light) improves with 2019.3 and onward. I'm on Unity 2019.2 and so using LWRP 6.9.2 and the 2D light performance doesn't scale well at all with many lights being added (a few hundred) - very, very poor performance. I am hoping this is improved in 7+ (that I'm assuming comes from Unity 2019.3+, since I see no update past 6.9.2 currently).
     
    BTStone likes this.
  38. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    We have been focusing on developing features first to get feedback, and are currently working on performance and addressing feedback and bugs that we have been getting.

    Both of these things are things we will be looking into.

    JasonBricco one thing that will improve performance for you now is reducing the render texture scale in the Renderer2DData asset. This controls the size of the light buffers. This can pretty safely be reduced to 0.5. But you may be able to reduce this further depending on your lights and scene.
     
    Last edited: Nov 11, 2019
    JasonBricco likes this.
  39. Meepo0

    Meepo0

    Joined:
    Nov 24, 2017
    Posts:
    27
    Hey, do you know why it is causing that, it is getting pretty annoying now and i cant do anything :( please help!
     
  40. ManuelMeisen

    ManuelMeisen

    Joined:
    Sep 14, 2019
    Posts:
    5
    Are the tiles in your spritesheet padded? If you dont pad the individual textures in your spritesheet,
    your tiles will have lines between them. 1 pixel in every direction is enough.
     
  41. altair2020

    altair2020

    Joined:
    Mar 6, 2011
    Posts:
    40
    Hey everyone, how do you get the "Shadow Caster 2D" to work ? is this working yet?
     
  42. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    271
    That's our recommended solution to this problem.
     
    Meepo0 likes this.
  43. kvam

    kvam

    Joined:
    Sep 28, 2019
    Posts:
    9
    Yeah, it works and it's very easy to use! Just add the "shadowcaster" script to the object you want casting the shadow and then there is a sprite-like shape you draw out for it. Once that is done just make sure the lights are set to cast shadows and play around with the settings of how shadows should be cast for each light2D.
     
  44. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,697
    It seems at the moment that sprite shaders built in Shader Graph that work under the lightweight render pipeline, do not work on the HD render pipeline. Will HD support these eventually?

    Also I tried implementing a lit sprite shader with a normal map. I think I got it working, but can you confirm the normal mapping is not supposed to look even remotely correct in 3D, it's more of a screen-space kind of projected thing?
     
  45. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    18
    Unity noob here, i can get global light to work but does not light up my Background layer (not sorting layer, actual layer) I have 2 layers, default and background and 2 cameras set up to simulate parallax by only showing one layer each, set to different depths (0 and -2). If I push cam 2 above cam 1 layer I can see it's lit but I can't see both layers at once anymore, also point light shows in the preview/scene but not when I run the game. Thanks!
     
  46. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    783
    When I create a new shader using the Sprite Lit Master node in Shader Graph (following documentation to add Texture2Ds), my sprites do not display the correct shading. Instead, any pixel in the sprite is colored to the max color value rather than being shaded based on the ligthness/darkness of the source texture pixels.

    sprite_lit_master_vs_sprite_lit_default_shader.png

    You can see how the cyan sprite's detail is displayed correctly.

    Here is the source texture:

    source_texture.png

    And Shader Graph:

    shader_graph.png
     
  47. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    For the moment there is no plan for the 2D Renderer to work with HD render pipeline. If you see a case that it would make sense (maybe with camera stacking?), it would be great to hear your use case.

    As for your second question, yes the 2D lights are more of a screen space thing and may look a bit strange in 3D.
     
  48. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    Are you trying to stack cameras with Universal Render Pipeline or do something else? At the moment camera stacking isn't supported by Universal Render Pipeline
     
  49. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    99
    I believe your shadergraph shader isn't setup correctly to work with Sprite Renderers. You will need to change the reference names to from Texture2D_xxxxxxxx to _MainTex, _MaskTex, and _NormalMap
     
  50. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    18
    Thank you so much for the reply!! I am using the cinemachine package for a virtual cam to follow the player and I have 2 other cam objects for a default/background layer . Most layered 2D games seem to use multiple cameras, is there a better route for parallax/scrolling that is compatible with 2D lights?
     
unityunity