Search Unity

Experimental 2D Lights and Shader Graph support in LWRP

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

  1. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    35
    Absolutely! Happy to provide any examples you think might be helpful. Attached is a screenshot of a side by side comparison of what I'm looking to achieve. I am adding a link to a zipped version of this example as well.

    Basically, I have my shaders on the left where they are using the stencil buffer to write the splatter effects only on the platform. I have not been able to duplicate these on shader graph and LWRP so I can't get the lighting to cooperate with them. HOWEVER... this had be thinking that the lights are already set up to only apply to certain sorting layers. I was wondering if it would be possible to have a decal system that uses the same system as the lights so sprites only show on certain layers? (kind of what I'm doing on the right side of the screenshot but with lights) If not, any help getting access to the stencil buffer in shader graph would be awesome.

    Link to project: https://drive.google.com/open?id=17EqdTPgJT9NXCRwAIWqpReMvcH97d6rL

    Thanks!
     

    Attached Files:

    Lars-Steenhoff likes this.
  2. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    Unfortunately, I don't have an estimate at the moment.

    If you did write a custom shader, there are a couple of obvious issues you would have to fix.

    The first is that you would want a new shader that is for opaque objects (zwrite and ztest) as sprites are all transparent.

    You may also need to make some changes to the lighting shader to properly support vertex normals. This would be a fairly simple change.

    After that though I'm not sure what sort of issues you might have.

    The other option you might have is Camera stacking. For each camera there should be a way to set the rendering settings you are using. However, I'm not entirely sure on the current state of camera stacking in Universal.

    Sorry I can't give you a better answer at the moment. But if you do get something working, it would be great to hear what you did to get it to work. I'm pretty sure you aren't the only one interested in doing something like this.

    Edit: Sorry just in case anyone else is interested, "you may also need to make some changes to the lighting shader" should actually be make changes to the normal rendering pass.
     
    Last edited: Aug 8, 2019
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,125
    Hey, no problem.

    Camera stacking seems to be the best option for this. I wasn't aware that you could just slot a different renderer onto a camera, that's really neat.

    So that works - I have a 2D Renderer on one camera and a Forward Renderer on another, and the first draws sprites with sprite lights and the second one draws 3D objects with 3D lights.

    The only big problem is that "don't clear" isn't supported for LWRP, so I have to have the 3D camera draw to a render texture that's on a RawImage. I know that some Unity staff has written that it was intentional that not clearing wasn't supported, but I can't for the life of me remember what the reason was.
     
  4. Elementa481

    Elementa481

    Joined:
    Sep 26, 2015
    Posts:
    3
    This package is wonderful and has such great potential!

    I'm having a small issue where I'm attempting to create depth in my 2D project based on their y positions. I have achieved this through a combination of adding the Sorting Group component on game objects and setting Project Settings > Graphics > Camera Settings > Transparency Sort Mode to Custom Axis with a Transparency Sort Axis of (0,1,0) (although I found out that those settings have been hidden now, probably because of the rendering pipeline asset). I can still see my added 2d lights through objects that are "in front" of them. Sorry if this has been brought up before.
     

    Attached Files:

  5. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    35
    What are the sorting layers of the objects you are trying to light? If the blue square is "foreground" and the red square "background" for example, you could change the settings on the light to only affect one or none of these layers and I think you would get the effect you are looking for. It's called the "Target Sorting Layers" option on your 2D light.
     
  6. Elementa481

    Elementa481

    Joined:
    Sep 26, 2015
    Posts:
    3
    Right now all of their sorting layers are default. So say I got a bunch of the squares scattered around the world as obstacles, I would want the light affect or be affected (blocked) by the squares within that sorting layer.
     
  7. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    129
    First off, i have to say that i absolutely admire the Unity staff support in this forum. Absolutely wonderful you taking time to answer what seems to be every question.

    Next, I am using ShaderGraph, and i cant seem to get alpha control to work on the SpriteLitMaster node using the Split->Combine trick. For details what i mean, with pictures, i posted this question already in ShaderGraph forum, as i assumed that the actual Split->Combine was a bad practice, but it seems the problem is with the SpriteLitMaster. It is also completely possible i forgot something basic, as my SG experience is minimal.

    SG forum post here


    What i do is take my Albedo (Color(4)), and before i input that into SpriteLitMaster's Color(4) input, i use the Split-Combine trick shown in the picture, to control Transparency "of all the pixels" that are input into SpriteLitMaster. However my Sprite stays completely opaque.

    Any suggestions?

    EDIT You can set alpha of the sprite via the Color dropdown inside your sprite renderer.
     
    Last edited: Aug 10, 2019
  8. Brucemax

    Brucemax

    Joined:
    Aug 7, 2019
    Posts:
    2
    Hey! My FPS decreased by half (from 60 to 28) after I set this new LWRP Asset to project setting. Is it normal or how to fix this??! (Build for Android platform, Xiaomi A1 device)
     
    Last edited: Aug 9, 2019
  9. laurG

    laurG

    Joined:
    Jun 1, 2017
    Posts:
    6
    Hi! I wish to leave some feedback!

    First off, love this feature! Will definitely help enhancing our 2D visuals.

    As for the feedback, not sure if anyone else asked for this, but it's definitely something that needs to be implemented for this new 2D lights.

    As far as I explored the feature, there is no way to integrate the lights with the Custom Axis sorting mode for sprites.

    This is a must have for 2D isometric games.

    Here's a screenshot from our game. As you can see the blue highlighted light works perfectly, but moving the same light behind a wall will make the light visible through the wall. In the screenshot there are 2 Sorting Layers - Ground and Floor 0 and the project uses a Custom Axis sorting mode for Y axis (0, 1, 0), that's standard for isometric 2D games.

    Would be AMAZING if there would be a way to have the full functionality of the SpriteRenderer sorting feature for 2D lights as well. That is Sorting Layer, Sort Order and Custom Axis sorting.
    upload_2019-8-9_21-2-14.png


    Thank you a lot and keep up the great work!
     
    tymerica likes this.
  10. Elementa481

    Elementa481

    Joined:
    Sep 26, 2015
    Posts:
    3
    I have the same issue as well and addressed it in post #154. Glad to know it's not just me.
     
  11. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    I'm glad you are enjoying the feature, and we appreciate the feedback.

    There is definitely some work left for isometric (and other like projection) games. However, at the moment I don't know when those issues will be addressed. We are interested in addressing them though.

    As mentioned previously we will be shipping shadow this year. While shadows will likely not fix this kind of issue for all styles of games, its possible it might for you. If you have a chance to try it, definitely post again with your results. It would be great to hear either way on how this worked for you.
     
  12. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,125
    Do you have a rough outline for how you expect the shadows to work? What you want it to do, what you don't think it'll do, that sort of thing?
     
    BTStone likes this.
  13. Wonka45

    Wonka45

    Joined:
    Aug 24, 2014
    Posts:
    10
    @Chris_Chu

    Chance of atlasing support this year?
     
  14. laurG

    laurG

    Joined:
    Jun 1, 2017
    Posts:
    6

    Awesome, @Chris_Chu!

    Thanks for quick response and info.

    Will definitely look forward to the shadow feature, since we're planning on adding shadows too. And if this might end up fixing this type of issue we have, that would be more than perfect!
     
  15. tymerica

    tymerica

    Joined:
    Dec 29, 2017
    Posts:
    5
    Since the URP is open source, do the devs take pull requests from game devs if they implement a module? Because i feel that implementing a layering system that interacts with custom axis sorting would be an infinitely useful thing, and I might maybe be able to get something like that working!
    If I make progress is it worth contacting a dev about implementation or is that not likely to occur?
     
  16. Sejuru

    Sejuru

    Joined:
    Nov 26, 2018
    Posts:
    9
    Hi, Im trying to work right now with the new 2D lights added to unity in this last version with the LWRP RP package and the Shader Graph package, I've created the 2D pipe renderer and used it in the project graphics settings. I can use the Lights perfectly in the scene view but they are not working in the main camera preview or game screen, just like it's shown in the picture, I'm also working with the new 2D Shader graph, the material of the bigpinkball has a 2D Renderer Sprite Lit Graph Shader. What can I do to make the lights work in game?
     

    Attached Files:

  17. Sejuru

    Sejuru

    Joined:
    Nov 26, 2018
    Posts:
    9
    Just fixed it, didn't noticed the Z value of the point lights, just changed it back to 0 and it works now
     
  18. HiddenTess

    HiddenTess

    Joined:
    Jan 7, 2016
    Posts:
    9
    It's not just flipped sprites that are having problems with normal-map lighting. Rotated sprites in tilemaps are also doing this:

    upload_2019-8-11_2-53-21.png

    In the past, I've had to do some binormal hacking in my own shaders (using VFACE or SV_IsFrontFace) to avoid the inside-out normal map problem in back-facing sprites, but I wouldn't expect a sprite rotated around the Z axis to be back-facing.
     
    BTStone and Lars-Steenhoff like this.
  19. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    It would be great if we do allow community pull requests, but I will need to investigate further on this matter, before making a comment one way or another.

    If I find out there are no problems doing so, we can chat about what you are interested in submitting.


    There were known issues with Tilemaps, Sprite Shapes, and 2D Skinned Sprites using normals. Since we didn't have normal maps previously, these systems weren't submitting some of the necessary vertex information required. This has been fixed in URP for 19.3 (however tilemaps seemed broken in URP again last I looked).
     
    Malkyne likes this.
  20. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    This is an editor change and unfortunately we won't have enough time to submit it as a new feature for 20.1. We realize this is really important, and we will do our best to get it in when we can. I'm sorry I can't give you a more specific timeline about this.

    Yes, we do, but I can only really tell you what I've done so far, which is that any number of lights can be shadow casting, but will have hard shadows (shadow volumes). At the moment the tooling is pretty limited.

    That being said, it looks pretty good. I'll have to see if I can post some images.
     
    cparki3 and Baste like this.
  21. HiddenTess

    HiddenTess

    Joined:
    Jan 7, 2016
    Posts:
    9
    Heh, yeah, I've been fighting with this for a while. :D

    Here's a related post I made back in 2017:
    https://forum.unity.com/threads/spr...-tangenttoworldandpackeddata-on-flips.503753/

    I made a shader with the old pipeline where it's mostly working, as long as I use inverted scale for all flips. This is the same tile in the old pipeline, with my own shader:

    upload_2019-8-11_14-46-51.png

    I wish this new 2D lighting system had come along sooner! If it were more mature, it would have been great for this game. I'll have to find an excuse to use it in a later project. ;)
     
  22. iiiiken

    iiiiken

    Joined:
    Dec 25, 2014
    Posts:
    1
    Nice work, thanks Unity team! Native 2D lighting is a great feature for Unity! Keep working on it, it gives a lot more perfomant results than lighting that uses 3D render pipelines. Im looking forward to use shadows feature when it will be published!
     
    cparki3 likes this.
  23. Roamer

    Roamer

    Joined:
    Oct 23, 2013
    Posts:
    4
    I'm getting 1.6kb garbage per frame from (I assume) the 2D renderer. Is this intended, or is this "editor only" garbage? It seems like a lot.

     
  24. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    Hey sorry, I haven't gotten back to you. I've checked out your project. I think ideally we would get the master node to support the stencil buffer as this may be something other people need for things that are not decal related. I can't say when this will be fixed though, as I haven't looked into what is involved in fixing this.

    Having said that, its pretty trivial to convert the Sprite-Lit-Default shader to be compatible with how you've done your decals. Make two copies of of Sprite-Lit-Default (for the splatter and surface). Change the shader name. Then just copy the stencil properties and copy the stencil blocks into each of the passes, and that will get it working (a few minutes of work).

    upload_2019-8-13_18-23-54.png

    There are some visual issue because of lack of alpha cutoff, but you might be able to fix that with a tighter sprite mesh (or adding alpha cutoff to the shader)
     
    Last edited: Aug 13, 2019
    cparki3 likes this.
  25. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    189
    The GC allocations is a known issue and will be fixed in a later release.
     
  26. Roamer

    Roamer

    Joined:
    Oct 23, 2013
    Posts:
    4
    Awesome! I hope that also goes for Light2D.LateUpdate(), I missed that one in my quick check. Thanks!
     
  27. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    35
    Thank you so much for the suggestion! I'll try it out this weekend and if all goes well I can share here if anyone is looking for the same effect. :)
     
    Chris_Chu likes this.
  28. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    That would be great. It should be straightforward to make the changes, but if you do have any issues don't hesitate to post them.
     
  29. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    4
    Hiya. It would be awesome if the Shader Graph Master Nodes exposed a vertex color input. Or if they had an option to turn off the use of vertex color. The color of sprites is a very useful property, and it would be really nice to be able to use it with shader graph. Right now there aren't many chances to use it in a different way than the traditional way because we can't control what the Master Nodes do with that information. If there was a vertex color input we could at least pass it white to stop the Master Node from doing it's own thing, or we could pass it any other color. An option to turn off the default use of vertex color could solve this too, I don't know if it would have any real performance impact, but it would be less user friendly, because we would have to do our own implementation of the current way vertex color works if we want it.

    Thank you for every thing. I hope you have a very nice day.
     
  30. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    35
    Thanks so much for your help! I was able to get them working and as promised, here are the completed shaders. Really appreciate the assist :)

    I'm also attaching a quick screenshot that shows the splatters working correctly. If anyone is curious on how to use I believe they currently work without modification but you can manipulate the read and write mask to determine how splatters show on a surface. The platform in the screenshot has the "surface" shader applied and the colorful paint marks use the "splatter" shader. And all of them play nicely with the new lighting system now!

    Thanks again!
     

    Attached Files:

    yuanxing_cai and Chris_Chu like this.
  31. Driven

    Driven

    Joined:
    May 31, 2013
    Posts:
    34
    2 quick questions:

    Is it somehow possible in shadergrapgh (sprite lit) with 2D Renderer to have a node which adds pure white color on top of the sprite which is not affected by nearby 2D lights color for like a "getting hit" effect?

    And second if there is no global 2d light in the scene, everything not hit by 2d lights is pure black, is there a way to toggle this like with normal lights in the editor by clicking the light bulb in the scene view?
     
  32. CircadianCity

    CircadianCity

    Joined:
    Aug 15, 2019
    Posts:
    1
    How would one add renderer features to 2D renderer ? As in
    for example.

    Actually what I'd like to do is to alter the computed light texture and dither it. We are working on a pixel-art game and currently 2d lights are too "smooth" and we want to pixelize the lighting. Now I could go around and edit Light2D-Point.shader or Light2D-Shape.shader (and related c# scripts). But what I'm wondering is, is there a way to customize rendering without modifying the S.R.P. source code ?
     
    WUIRGN_NW, OFG and Coffein like this.
  33. Coffein

    Coffein

    Joined:
    Jan 22, 2016
    Posts:
    17
    I would also be interested in this
     
    OFG and CircadianCity like this.
  34. OFG

    OFG

    Joined:
    Dec 6, 2017
    Posts:
    9
    Pls i wonder to do this too.
     
  35. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    Right now there isn't a way to do what you want to do. However, I've noted your post, and its something we will look into.
     
  36. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    37
    I'm really sorry I've taken so long to get back to you on this. I've talked to our legal department, and they did tell me we have the Unity Contribution Agreement https://unity3d.com/legal/licenses/Unity_Contribution_Agreement

    However, this doesn't really cover what happens if the contributor's code has been plagiarized from open/closed source. If that code is the foundation for a feature we have to consider what happens to users projects if we have to disable that code and what happens to those users projects that ship with that code?

    I think for bug fixes, or simple changes, we should be able to accept pull requests (assuming the PR is something we approve). But unfortunately, at least at the moment, I don't think we can take large code changes at least not as part of SRP.
     
    Last edited: Aug 21, 2019 at 10:24 AM
  37. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    460
    I have 2 issues that are concerning me, hoping they get ironed out.

    1st issue is a simple one that others I think have stated and that is the lack of setting the sorting axis in the editor when using the LWRP. The option disappears once you add the pipline. Its an easy work around to set it in code but is convenient to have in the editor.

    2nd issue has to do with 360 degree point lights. They have a line at the bottom that shows up. @AndriiM had pointed it out a few months back here. They also stated it was fixed in the beta.

    When I start the game all the lights look fine. Once I start moving the camera/player around the line at the bottom flickers on and off. When I stop moving the camera/player the lines may or may not be visible. There is a light attached to the camera/player and the line doesn't show up at all on that.

    I tried to use the pixel perfect camera and it solves the problem with the stationary lights in the scene but it now shows up on the one attached to the camera/player.

    I have tried 2019.2.0, 2019.2.2 and 2019.3.0.
     
  38. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,125
    Oh right, forgot all about that. We were also seeing the 360 degree lights having a single-pixel line. It's dependent on the light's screen position, but it's completely reproducible.
     
  39. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    460
    I also found that if the light isn't on a pixel position it can cause the 1 pixel line.

    Another problem I've run into with 2019.3 is that the alpha blend on overlap causes the light to black out everything when lowering the intensity. Even with a global light source it appears as a black circle. Take off alpha blend and it works but isn't the effect I am looking for.
     
  40. Enixus

    Enixus

    Joined:
    Jul 13, 2019
    Posts:
    2
    Workaround: I discovered, that this line disappears, if you rotate the transform of the light, so its != 0.