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

4574821--425203--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: Unity Editor Beta Releases
    4574821--425662--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

  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
    4574821--425206--image1.png
  2. Select the created Pipeline Asset then select and change General → Render Type → Forward Renderer to Custom
  3. Assign the created 2D Renderer to the data field.
  4. 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!

14 Likes

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.

2 Likes

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

3 Likes

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.

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)

1 Like

What about performance ?
This new system is more faster than the default one ?

In my game I build all the sprites in script. Currently I see no access to the ‘Target sorting layers’ via code in Light2d

1 Like

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.

4 Likes

Sorry no-weekend, this needs to be fixed. It won’t be fixed in the next package release, but hopefully one soon after.

2 Likes

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.

6 Likes

There’s still the issue with the black camera feed (background) using LWRP and AR Foundation. Any ideas when this might be fixed?

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.

4 Likes

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:

12 Likes

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.

4 Likes

That would be awesome! We are using Spine as well and would really like to leverage the 2D lights. Really appreciate it :slight_smile:

2 Likes

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 :slight_smile: So you actaully have everything you need to do this already :wink: Can confirm the included 2D shadergraph shaders work

1 Like

@Chris_Chu @rustum

Any ETA for isometric support ?

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.

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 :slight_smile:

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.

2 Likes