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

Official Experimental 2D Lights and Shader Graph support in Universal RP (previously LWRP)

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

  1. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    2D Lights in 2D Renderer in LWRP.gif

    We’ve released a 2D Renderer in an experimental namespace in LWRP.

    This version includes:
    • 2D Lights
    • Lit and Unlit Sprite Masternode in Shader Graph
    • Pixel Perfect Camera component
      • This will be the new home for Pixel Perfect moving forward. The standalone package will still receive bug fixes, but new features will only be added here.
      • This is the same component with the same workflow as the one in the Pixel Perfect package. The main change is that Pixel Perfect is now compatible with the 2D Renderer in LWRP.



    Getting Started
    Installing LWRP
    1. Download and install the latest Unity 2019.2 beta, here: https://unity3d.com/unity/beta
    Lightweight RP.png

    2. Get the LWRP version 6.7.1 from the Package Manager in Unity
    3. Select the packages you wish to install and click Install.
    Configuring the 2D Renderer
    image4.png

    1. Create a new Pipeline Asset by right clicking in the assets view of the project window, and selecting Create > Rendering > Lightweight Render Pipeline > Pipeline Asset
    2. Create a new 2D Renderer by right clicking in the assets view of the project window, and selecting Create > Rendering > Lightweight Render Pipeline > 2D Renderer
    image1.png

    3. Select the created Pipeline Asset then select and change General -> Render Type -> Forward Renderer to Custom
    4. Assign the created 2D Renderer to the data field.
    image3.png
    5. In the graphics settings set your Scriptable Render Pipeline Settings to use the created Pipeline Asset​

    The 2D Renderer should now be configured.

    Samples
    Get the 2D Renderer samples here:
    https://github.com/Unity-Technologies/2d-renderer-samples

    Documentation
    Click on the View Documentation link in the Package Manager.

    Compatibility:
    The 2D Renderer is designed to work with 2019.2 and is incompatible with any previous version of Unity.


    Upgrading
    If you are installing the package into a Project with pre-existing Prefabs, materials or Scenes, you will need to upgrade any materials used to a lighting compatible Shader. The following functions allow you to do so. Do note that this is a one way process and cannot be reverted.

    Upgrading a Scene
    To upgrade the currently opened Scene, go to Edit > Render Pipeline > Lightweight Render Pipeline > 2D Renderer > Upgrade Scene To 2D Renderer

    Upgrading a Project
    To upgrade all Prefabs and materials in your Project, go to Edit > Render Pipeline > Lightweight Render Pipeline > 2D Renderer > Upgrade Project To 2D Renderer


    Please share your experience with the tools by replying to this post or creating a new one. How does this feature help you achieve your desired outcomes? What works as expected? And what doesn’t? We’re excited to hear back from you!
     
    M_MG_S, NotaNaN, Rallix and 11 others like this.
  2. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    What about using the alpha channel for HDR stuff? CSR 2 devs used the alpha channel for masking out the bloom and we did bloom amplification using the alpha channel in Grand Dad Mania. Perhaps it can be a very good option in cases where true HDR is not needed except for a better bloom or some other effects that otherwise do not use the alpha channel. It's a win-win situation since we'll save performance by not using floating point buffers on highend-ish devices and retain the original colors by not using remapping on lowend devices.
     
    Last edited: May 29, 2019
    Chris_Chu and willgoldstone like this.
  3. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,979
    Tasty, will fire this up and give it a spin later.

    Im currently using spine to do bone based 2D animation due to sprite swapping not being supported in the animation v2 package currently, and I am hoping I can get the included spine shader to work with LWRP so I can leverage the lights.

    If not then I will write a replacement and post it here for people to use as I know a number of the community are using spine currently until Anim V2 matures a bit (removal of PSB only support, addition of sprite swapping, FFD etc) as from looking at their shader quickly it doesnt seem to do anything too difficult to recreate using LWRP
     
    ysys-jeff, cparki3 and zIyaGtVm like this.
  4. Stenix

    Stenix

    Joined:
    Jul 14, 2014
    Posts:
    1
    In a small project of mine i tested this out. It worked fine on my prefabs, but not the non-prefab sprite-renderer components. I fixed this by simply removing the components and adding them again. While it worked fine for me, for bigger projects it might be more tedious.
     
  5. no-weekend

    no-weekend

    Joined:
    Jun 7, 2013
    Posts:
    12
    I have just tried this in my project, it works really well.
    Shader graph did crawl once and then kinda weirdly crash and cause Unity's text to all garbled. but after a restart it seemed to be fine.

    One thing I am really wanting is some form of shadows and maybe ways to mask areas from certain lights (ie. from the global light)
     
    foxnne likes this.
  6. OscarLeif

    OscarLeif

    Joined:
    Jul 17, 2016
    Posts:
    69
    What about performance ?
    This new system is more faster than the default one ?
     
  7. no-weekend

    no-weekend

    Joined:
    Jun 7, 2013
    Posts:
    12
    In my game I build all the sprites in script. Currently I see no access to the 'Target sorting layers' via code in Light2d
     
    owlgrey likes this.
  8. no-weekend

    no-weekend

    Joined:
    Jun 7, 2013
    Posts:
    12
    What also would be good is a direction for the global light, (just like the global 3d light) couple that with normal maps and a shadow and you have a top down day/night cycles.
     
  9. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Sorry no-weekend, this needs to be fixed. It won't be fixed in the next package release, but hopefully one soon after.
     
    owlgrey and no-weekend like this.
  10. foxnne

    foxnne

    Joined:
    Apr 18, 2016
    Posts:
    59
    Is there any possibility of supporting Light2D while also rendering a "3D" directional light?

    Currently it seems it's not possible to get both types of lights. That's unfortunate, but it seems I need to choose between my sprites being tilted up like a pop-up book to get real shadows from the "sun" directional light, or put them back for regular 2D spot lights but no shadows.
     
    enhawk, theraje3, rustum and 3 others like this.
  11. MartinGebske

    MartinGebske

    Joined:
    Jun 18, 2013
    Posts:
    13
    There's still the issue with the black camera feed (background) using LWRP and AR Foundation. Any ideas when this might be fixed?
     
  12. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Shadows are planned for later this year. As for having a way to set a direction on the global lights, this is something I've thought about as well. This is something I'd like us to put in this year.
     
  13. AndriiM

    AndriiM

    Joined:
    Jul 25, 2012
    Posts:
    7
    EDIT; Scratch that, seems fine in the beta build 4

    Hey @Chris_Chu ,
    I think there is a bug with 360 point light. If you turn on Volume Opacity, there is a gap between 360 and 0 degrees. Looks like this:
     
    Last edited: May 30, 2019
    Zoo4125, Bobcatn777, KiraTile and 9 others like this.
  14. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    I think Freeform Lights would benefit a lot also from having the option to set a parallel direction like some kind of parallel light. One use that I've been applying a lot for freeform lights is kind of semiglobal light, where every room in a scene can have its own global/ambient color temperature without a lot of complications. So I've been finding myself using Freeform Lights a lot more than Global Lights for that reason. The way they handle normal maps when used as a semiglobal light doesn't fit well though; the light direction should be parallel when used like this, not coming from the origin point.

    If it helps, I can think of three ways to make this available:

    One is to have the option in both Freeform Lights and Global Lights to toggle between the default way they handle normals and a parallel direction. I think it's important to keep the current ways they work available, because they are both also useful. To be honest, this would be enough for me. There is a problem with this though: when global lights can have direction, it makes sense to be able to have more than one per layer and blend style.

    A second way to make this available would be to add a Parallel Light and then add the option to limit it to a freeform Area. Then you could replace Global Lights with an option to change ambient light in a window, the same way it works on 3D. You could have an ambien color for each Layer and Blend Style. Or you could just put an ambient light option directly on the sprites, I think it would be easier to think about, and I haven't really found a use for having different global lights for different blend styles. You could also collapse Parametric Lights and Freeform Lights into Point Lights, specially Parametric Lights, because Point Lights could replace them easily if they had the options of Sides, Angle Offset and maybe Fallof offset.

    A third way is to simply add Parallel Light and a Freeform Parallel Light. I still think it could be better to replace Global Lights with an ambient light panel in a special window, or an ambient light option in the sprites.

    Any other way I can think of is really a convination of this three. Anyway, it's awesome to finally have 2d Lights integrated in Unity, I'd love to have some kind of freeform parallel lights, and thank you very much for everything.
     
  15. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    41
    That would be awesome! We are using Spine as well and would really like to leverage the 2D lights. Really appreciate it :)
     
    MadeFromPolygons and foxnne like this.
  16. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,979
    Actually I was happy to see that the LWRP shaders work with spine without me needing to update them.

    I had messaged the spine devs and they said their shader does nothing special, any sprite shader will work :) So you actaully have everything you need to do this already ;) Can confirm the included 2D shadergraph shaders work
     
    rustum likes this.
  17. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
  18. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    There are some issues with tile maps at the moment. Unfortunately, the tiles in the tile window appear unlit (black). This is an issue we will try to address relatively soon (not sure when), and depending on your use case with tile map, the lighting may work for you when this is fixed.

    However, there is also a chance the current lighting system might not suit your needs. I think this would be a great topic to discuss once more people have had a chance to try out the lighting system.

    Thanks for the feedback. I definitely like your idea of adding a parallel light option to more than just the global lights and I think the point you brought up about global lights if we add a parallel light option to it, is a good one to consider.
     
    Last edited: May 31, 2019
  19. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    Indeed, I have will have my own sorting system because unity sorting doesn't fit at all with my requirement so waiting for that thread with pleasure :)
     
  20. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I haven't worked with Unity 2D yet and wonder what makes the lwrp 2d renderer better than the built-in one? Some sort of comparison table would be very useful as well.
     
    NotaNaN and Sylmerria like this.
  21. arsnyan2002

    arsnyan2002

    Joined:
    Apr 30, 2019
    Posts:
    30
    Is it me or there's a huge problem with that when you use Tile Palette?
    Tiles don't want to show up in palette and I guess this is because it works like a scene but as there is no light source, user cannot see a thing at all.

    P.S. You can see that I chose a bunch of tiles and I can also put them at scene. Though I can't see them in tile palette.
    Also, I used Global Lightning to make a scene look ok.
    upload_2019-6-2_14-2-56.png
     
  22. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    I'd love to get a clearer understanding of what outcome you're trying to achieve here. Are you trying to get shadows to be received by a sprite? If so, does it have to be from a 3D light? And finally, the object that is casting those shadows, is that a sprite or a 3D object?
     
    foxnne likes this.
  23. foxnne

    foxnne

    Joined:
    Apr 18, 2016
    Posts:
    59

    Well, in my eyes the issues are tied to being a top-down game.

    The goal would be to have a single source of light drive the overall brightness of the scene, like the new global light, but be able to cast shadows off buildings/objects/characters etc. in a way that simulates a day/night cycle.

    In my project, for lighting it seems I'm limited to a few options, neither of which allow me to achieve this goal:

    I can make my project mostly 3D, and tilt character/object sprites up similar to a popup book. I then can use a 3D directional light to get nice accurate shadows with the light acting as a sun. This is easy to achieve using a quad and custom shader, and I don't have any issues creating this. However, I can't use much else for point lights or any other lights as 3D point lights will behave strangely when behind a tilted up sprite.

    The other option is to go pure 2D and have regular sprites, and use these new lights. However, even when the shadows are implemented I can only imagine they will be collider-based. This means character animations won't really work out unless they are cast from a simple collider that won't match the characters sprite. Solutions like 2DDL pro and other lighting assets work well for simple characters or only on walls, but none offer the ability to have a global light cast shadows all at the same angle, like you would expect a global sun to behave.

    The perfect solution, in my eyes for top down games, would be a 2D global light that uses a heightmap for each sprite to calculate directional shadows, imitating a "sun". The heightmap could be attached similar to how normal maps are to be attached as a secondary texture, or similar I believe.

    I don't necessarily have to have real time shadows for every light. But a global light that can cast "fake" shadows from sprites for a day/night cycle would be amazing.

    Edit: https://www.mattgreer.org/articles/dynamic-lighting-and-shadows/

    Maybe something like described here in part 2?

    One more smaller request would be the ability to have two 2D lights overlap without increasing brightness, or the ability to specify a ceiling so overlapping lights wouldn't increase past a certain brightness. Currently if I have multiple characters that are able to cast light, I can't have too many close together or things become blown out.
     
    Last edited: Jun 4, 2019
  24. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    We are working on a fix for this issue
     
    arsnyan2002 and foxnne like this.
  25. EvOne

    EvOne

    Joined:
    Jan 29, 2016
    Posts:
    173
    Does this package have any problems with Post-processing stack compatibility?
    Is this a bug, or should it be so? :)
    -Here is a screenshot with the standard bloom effect from the standard post-processing profile -I could not find the settings in the 2D LWRP asset that would remove these creepy "steps" instead of the smooth gradient of the bloom.

    Yes, turning on the HDR checkbox on the quality tab makes the gradient smooth, but what to do without HDR?
    At the lower intensity of the effect, the “steps” are less visible, but they are still present.

    P.S. Sorry for google-translate.
    2019-06-05_18-38-54.png
     
  26. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Can you do me a favor and file a bug report through the bug reporter? That way I can get your project and take a look at what is happening.
     
  27. EvOne

    EvOne

    Joined:
    Jan 29, 2016
    Posts:
    173
    But I can not! :confused: -All my attempts to send a report end with this error when packing the attached project! :mad:
    This has never happened before.

    Why is it not indicated reading which file exactly caused an error - I do not understand!
    - This software is not for housewives - why hide the "extra" information from us?
    If I had more information about the problem encountered during data collection, I would understand and correct it, but ...
    -How I now send a report about the bug if the "Automation" that should collect the data -does not work, and neither the reboot Win, nor the cleaning of the Unity temporary directories (which I know, but not the fact that about all) does not help!
    Cut from the project Lib directories, etc. - also did not help.

    I sent bugreports many times before - this is not the case until now, but this time - I just do not know what the matter is.

    2019-06-06_14-35-03.png
     
    Last edited: Jun 6, 2019
    MadeFromPolygons likes this.
  28. EvOne

    EvOne

    Joined:
    Jan 29, 2016
    Posts:
    173
    Here is a clean project, without folders and files created by Unity. When I unpack it and open it in Unity - everything I wrote about bloom and “steps” earlier - I see it in this project, again.

    I do not know if it will help you,
    but it looks like this is all I can do now... :((((((((((((((((((((((((((((((((((((((((((((((((((((((
     

    Attached Files:

  29. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    I don't think I'll have time to look at it today, but I'll try and look at it sometime soon. Sorry you had issues with the bug reporter, but thanks for the project.
     
    EvOne likes this.
  30. foxnne

    foxnne

    Joined:
    Apr 18, 2016
    Posts:
    59
    Will it be possible to access some of the lighting data through Shader Graph in the future? The possibility to create custom lights and behaviors would be great.
     
    NotaNaN, oscarAbraham and no-weekend like this.
  31. sambess

    sambess

    Joined:
    Sep 27, 2015
    Posts:
    4
    Hello !
    I Have a problem with the 2D light. In my scene, i see the light but my camera don't renderer the light.

    upload_2019-6-7_17-33-57.png
     
  32. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    Have you tried checking the z coordinates of your lights and camera? Lights need to be in front of the camera to work in the game view.
     
  33. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Hi. I'm Finding that none of the LWRP particle shaders work with the experimental 2d renderer type. When I change it back to the Forward Renderer, they work again. Is that to be expected?
     
  34. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    Hi @rustum I'm trying to understand the lwrp use cases, we are creating an open world 2d game, this game is NOT intended for mobiles but for pc/mac. Do you think there is benefit of using the lwrp for this ?
    If so why and what will we lose by using it ?
     
  35. dquek

    dquek

    Unity Technologies

    Joined:
    Apr 17, 2018
    Posts:
    70
    Hi EvOne,

    This issue could be due to visual studio being opened and it locks some files inside the project folder.
    You can try to close the IDE before submission.

    This issue actually was fixed in one of our previous releases.

    So sorry for the inconvenience!

    Cheers,
    Darren
     
    EvOne likes this.
  36. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    The shaders for LWRP, like the particles, are actually set up to work with the forward renderer, not the 2D renderer. In the next version of LWRP particles will be rendered but they will be unlit.

    If you need 2D lit particles, you can create a new material, with the Sprite-Lit-Default shader then assign that material to the particle system.
     
    oscarAbraham and EvOne like this.
  37. EvOne

    EvOne

    Joined:
    Jan 29, 2016
    Posts:
    173
    It seems that in my case the reason is not in the visual studio. -After restarting the operating system, launching the Unity without any additional launches of other programs, trying to send a bug report, I again received a similar message.
    Unity version 2019.2.0b3
    I will check later after upgrading to last beta
    2019-06-11_15-41-31.png
     
  38. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    Hii, is there any plans on adding reflection ? currently the only way I know of doing this is render the screen to a texture
     
    foxnne likes this.
  39. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    87
    Tried the package, works great. I have a question. For a sprite renderer to be affected by the light it has to contain the sprite-lit-default material. Given a sprite renderers can contain only a single material, how can I use the light with my custom effect created in shader graph?
     
  40. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    We have talked about it, but don't yet have firm plans for it at the moment.

    You should only need a single material. Assign your shadergraph shader to a material and assign that to your sprite. Also make sure your shadergraph uses the Sprite Lit Master node. If you are having issues with this I would recommend looking at the documentation. If your inputs are setup correctly, and everything is connect right it should just work.
     
    Last edited: Jun 12, 2019
  41. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    87
    Indeed! Using the master node works, thank you very much.
     
  42. eniliosarcos

    eniliosarcos

    Joined:
    Jul 4, 2016
    Posts:
    2
    This package is amazing. Could it be used in the light module of the particle system? because I tried to do it creating a prefab with component light 2d of the LWRP, but i noticed that was not compatible when i dragged the prefab into the light module in the particle system.
     
    Last edited: Jun 12, 2019
  43. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Its always great to hear that people like the work we've done. Sadly, our lights are not yet something the particle system can emit.
     
    eniliosarcos and foxnne like this.
  44. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Sorry it took me so long to get back to you. I think there may be a bug with the way lights above one are rendering with SDR. For now you will have to enable HDR on the lightweight asset if you want to get rid of the banding.
     
    EvOne likes this.
  45. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    Amm good to hear, Guess we'll do it old school for now ^^
    The package looks awesome right now, any public roadmap available ?
     
    foxnne likes this.
  46. SomehowLuke

    SomehowLuke

    Joined:
    Nov 11, 2015
    Posts:
    34
    Hi, with 2d Lights: is there a way to give the darkness a tiled texture? Right now when I turn of the lights, all turns black of course but I would like to give the darkness some kind of roughness (like a fog of war) . Is that possible or do I have to work with masks?
     
    foxnne likes this.
  47. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    I'm sorry to say, while we do have plans for 2D lights, we don't have a roadmap to share at the moment.

    Hm, depending on what you want to do, you might be able to achieve this effect with masks. Do you have an example of this effect that you could post?
     
  48. SomehowLuke

    SomehowLuke

    Joined:
    Nov 11, 2015
    Posts:
    34
    Hi and thanks for the answer. I try to explain what I want to achieve, but if it does not work, I will setup a sample to explain it further.

    Once I set the LWRP with 2D Rendering everything turns black (which is perfect) and then I add for example a Point light where things get rendered inside the radius. I have moving objects that move from A to B to X and I only want it to be seen inside the light radius.
    So far so good and with the current lights it works perfect.
    Now I want to go a little further. I dont want to have the black shadow for the unlit parts, I would like to have a texture for the black (for example some kind of noise). In that way the unlit parts of the level would have some kind of structure instead of being totally black.

    What I have tried so far:
    I tried to set a global 2D light, that affects only the background with very low intensity. But unlit sprites are also seeable in black but what I would like is them to be transperent.

    What I want to try next:
    I would add a radial Mask to the light source itself so the sprites will only be rendered inside the light and not be seen outside its radius. I would need to use Alpha Mask Asset to achieve a nice fade out at the mask border.

    My question is, if there is a way with the 2D lights to achieve that without an additional mask it would be easier to do.
    1. Is there a way to give the black (unlit areas) a texture
    2. Is there a way to tell the sprite-shader that unlit pixels of an sprite should be not rendered, in that way I would keep my current setup with the slightly lit background and set the moving elements to the adjusted sprite shader.

    Hope that explains what I want to achieve.

    Best,
    Markus
     
  49. arkogelul

    arkogelul

    Joined:
    Nov 14, 2016
    Posts:
    105
    Is the 2D renderer improving performances for 2D games in any way ? (I'm not using lights in unity)
     
  50. sachanhardik

    sachanhardik

    Joined:
    Apr 13, 2018
    Posts:
    5
    ETA for fixing the bug with isometric tilemaps?