Search Unity

Unity Experimental 2D Lights and Shader Graph support in LWRP

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

  1. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Hi, just discovered this. On a tutorial I was watching they created an asset in Rendering > LR Pipeline > 2D renderer. That's no longer there. Is there a reason why or is it not needed? The tutorial says for 2D to create a custom renderer type instead of Forward Render for 2D games. Thanks.
     
  2. Scatabrain

    Scatabrain

    Joined:
    Aug 28, 2015
    Posts:
    17
    There is a minimum version to see it in the package manager. It is not enabled by default.
     
  3. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Ah, yep, realized that after I posted. Got it all working now.


    Now next question - I understand it's all 2d rendering, but is there a way to have a light shine from BEHIND a sprite, or is the only option to use Freeform to get that backlit effect?
    Edit: Actually no freeform doesn't work, either, obviously as it still lights the front face of the sprite...hm....
     
    tymerica likes this.
  4. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    Are you talking having a rim light effect? If so you can do that with masks. There are samples....somewhere...on how to do this. I'll have to look into where they live at the moment.
     
    CoCoNutti likes this.
  5. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    72
    Does this mean the sprite masks are working? I cant seem to get masks working:
    Without LWRP (Working):

    upload_2019-7-11_20-32-44.png

    With LWRP on mask is ignored (or better put : Its always outside mask)
    upload_2019-7-11_20-34-34.png

    With LWRP (if i set it to show in mask then its completely hidden even)
    upload_2019-7-11_20-36-51.png
     
    EvOne likes this.
  6. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Yes, excellent thank you
     
  7. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Found it in the sample project here:
    https://github.com/Unity-Technologies/2d-renderer-samples
     
    Chris_Chu likes this.
  8. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    72
    Ah i get it. It's the Mask of a image attached to a sprite rather then the sprite mask variant. So its a completely different mask. That's mask image inside the sprite tells what part reflects or not while the other broken mask hides part of sprites from other sprites.

    So for me that Mask has lifted and i see the light.
     
  9. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Another question - with this new lighting system, do sprite masks not work using this system? Can't seem to get one working.
    Thanks
     
  10. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    72
    Well i did gave an example at #105 sprite masking is working when you set scriptable pipeline to None and they stop working when you set them to LWRP
     
  11. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    72
    BUT if you mean the light setting (indicating where you want your sprite reflect light or not) that mask IS working but you have to add a extra texture and mark it as shown here
     
  12. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    72
    I saw we have a new version of the LWRP (6.9.0. I tried sprite masking but it didnt work still. (I was not expecting it as it was not to read in the changes doc but you never know do you.

    I found a way however to get sprite mask working again and that is by setting a Custom range:
    upload_2019-7-12_20-8-6.png
    and as you can see then the sprite mask works.
     
    wagnerps and CoCoNutti like this.
  13. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Sorry was very late at night when i posted it and hadn't read up
     
  14. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    37
    They have mentioned that shadows / blockers are on the roadmap and should be coming later this year :)
     
    tymerica likes this.
  15. tymerica

    tymerica

    Joined:
    Dec 29, 2017
    Posts:
    5
    yes I was just reading that! thanks!
     
  16. volvis615

    volvis615

    Joined:
    Nov 10, 2013
    Posts:
    8
    Hello,
    Will the custom sort axis option that was in the default renderer be brought to the 2D renderer at any point?
     
  17. Coffein

    Coffein

    Joined:
    Jan 22, 2016
    Posts:
    17
    Hey! As far as I know the axis sorting works, but is currently hidden once you select a SRP. To set it, deselect the asset in the preferences, adjust, then reselect it
     
    volvis615 likes this.
  18. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    208
    mountblanc likes this.
  19. HaroldReyiz

    HaroldReyiz

    Joined:
    Oct 20, 2017
    Posts:
    3
    Thanks, I really appreciate it. In the meantime, I'm trying to apply a quick fix until you guys can resolve the issue. Can you give me any pointers ? Is there a specific part of shader code that is hard-coded to apply lighting on only XY? Or maybe I have to change some y coordinates with some z coordinates in the scripting end, I don't know, just guessing. We are trying to decide if we are going to use 2d lights or not, so the solution doesn't need to be perfect. I just want to get it working and present it to my team. Thanks in advance!
     
  20. volvis615

    volvis615

    Joined:
    Nov 10, 2013
    Posts:
    8
  21. mountblanc

    mountblanc

    Joined:
    Sep 24, 2015
    Posts:
    72
    meanwhile it seems LWRP is being replaced/changed as mentioned here.
    So not quite clear on how to proceed.
     
  22. theraje3

    theraje3

    Joined:
    Mar 16, 2014
    Posts:
    2
    Really really looking to this. So nice feature so far, that extra detail will top it! as no-weekend says, Awesome day night cycles. I was trying some lights for getting this done but i couldnt find any close to a directional light.

    Great job so far!! :)
     
    foxnne likes this.
  23. DavidC02

    DavidC02

    Joined:
    Jul 19, 2011
    Posts:
    147
    How would you achieve sun shafts right now?
     
    foxnne likes this.
  24. lousdarvin

    lousdarvin

    Joined:
    May 9, 2019
    Posts:
    1
    Oh...Thank you so much!
     
  25. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Ah......what.......>>??? ><
     
  26. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    This can be achieved by turning increasing the volume opacity on appropriately shaped light


    LWRP has changed its name to universal. There have been measures taken to make sure projects using the old namespace won't break with this change.

    The only change when writing code for the 2D Renderer should be to use the Universal namespace where you would have used the LWRP namespace.
     
    mountblanc likes this.
  27. Raspilicious

    Raspilicious

    Joined:
    Jun 21, 2012
    Posts:
    24
    I'm loving these new lights! I've already started using the Parametric light instead of the Point light for the 'black line' issue, and it's working fine at the moment.

    Is there a way to adjust the path for the Freeform light? I see there is a Vector3[] shapePath but I can't assign data to it. What would be a good way to assign a new path for it at runtime?
     
  28. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    I'm glad you're enjoying the lights. We don't currently have a way to adjust the path at runtime at the moment, but we will be looking at options for future versions.
     
  29. Raspilicious

    Raspilicious

    Joined:
    Jun 21, 2012
    Posts:
    24
    I see. Thanks for getting back to me so swiftly! I can't wait. :)
     
  30. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    Ok I get what you want now, and without a shader change this isn't possible. I'm unable to help you with this at the moment but if the mask don't work and if you don't get community help with this, I'll can post some code snippets or upload files. But you'll have to wait a couple weeks.

    There might be some benefit, but it will be marginal. We will be doing performance improvements in upcoming releases some of which will improve performance of both lit and unlit games.


    If you are talking about the black tile palette, the fix is in for Lightweight RP 6.9 and Universal RP 7.0
     
  31. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    491
    Don't know if this is the appropriate place to post or if anyone can help. I'm absolutely dreadful when it comes to shaders and I want to create a sprite shader utilizing the 2D lighting system (based on the current sprite shader) for black and white influenced by this greyscale shader https://forum.unity.com/threads/sprite-shader-with-greyscale.222693/

    Is anyone able to help? Can it be done? Thank you
     
  32. AK-TOG

    AK-TOG

    Joined:
    Jul 24, 2019
    Posts:
    1
    Loving the package so far.

    However, encountered this minor issue and thought to ask if its expected behaviour before working around it. Apologies if this has been brought up already.

    It appears that the flip setting on sprite renderers causes lighting to be mirrored.

    flippednormals.png

    In this example the normal mapped sprites surround a point light. The top right group are not flipped and have the expected highlights.

    The left sprite renderer has it's flip set on X, the bottom on Y and the bottom left on X and Y. This group is lit on the opposite side from the light on the axis of it's flip.

    This is on a10 and a7 with LWRP package 7.0.0 and 6.7.1 respectively. The pictured example project attached.

    Thanks,
    Ak.
     

    Attached Files:

    Malkyne and EvOne like this.
  33. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    Thanks for posting this. Will add fixing it to our list of work to do.
     
    AK-TOG and mountblanc like this.
  34. DavidC02

    DavidC02

    Joined:
    Jul 19, 2011
    Posts:
    147
    Thanks Christ, but I'm talking about something like this, not a texture like they did on Ori and the Blind Forest or Light Fall. Any ideas for that?
     

    Attached Files:

    Last edited: Jul 28, 2019
  35. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    Ah I see. I don't think this has a simple solution and would likely require additional engineering. If I'm able to come up with something simple though I'll post and/or message you about it.
     
  36. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,070
  37. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    132
    Im a little confused regarding the "mask not working yet" (and i'm currently only interrested in usecases pertaining to in-shader masking). Do you folks mean that when the texture is plugged in the material inspector (T2D with _MaskTex reference in the shader), it does not currently work? Because that's what i'm experiencing. I might be misunderstanding something, is THAT what @Chris_Chu explained, will be fixed later?

    Also, to work around this, we can simply ignore the MaskTex input in the inspector, and implement our own masking inside the shader using a T2D mask Multiplied with Albedo (etc)? Or will that be bad practice to do for now. It works for me, but i assume it will become unnecessary, once the above masking is fixed?

    Thanks for clarification
     
  38. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,483
    I just want to add to the shameless feature request :

    If there is light, there must be shadow

    :D

    I know this is on the road map, but this is really important.
     
    tymerica, Raspilicious and pahe like this.
  39. Wonka45

    Wonka45

    Joined:
    Aug 24, 2014
    Posts:
    10
    @Chris_Chu @rustum
    Hey, I switched my project to 2019.2 LWRP and 2D renderer -> couple issues with draw calls, because some sprites had just layer 1 in rendering layer mask?

    Anyway, now to the real issue: Im using sprite atlas for my sprites, how do I get normal maps to work? I applied the normal map as secondary texture to one sprite, but it dont work
    do I have to also make sprite atlas for my normal maps and does it have to same size as the other sprite atlas? very confusing

    EDIT: there seems to also a problem with normal map when character is flipped x scale
     
    Last edited: Aug 1, 2019
  40. kgwer2

    kgwer2

    Joined:
    Jan 4, 2016
    Posts:
    1
    when using Pixel Perfect Camera with Crop x,y and stretch fill,
    mouse position and object position not match.
    like OnMouseEnter Method, don't call exactly when mouse entered position over the object.
    this issue find after change this LWRP pixel perfect camera.
    not LWRP 2D pixel perfect camera is fine.
    how can i fix this issue.
     
  41. Ducat

    Ducat

    Joined:
    Jan 13, 2017
    Posts:
    4
    Hey there.
    I'm expiriencing the problem with my normal maps rendering.
    If you flip the sprite in-game (set ScaleX to -1), it starts to shadowing itself somehow...
    And it's only with Normal Maps turned on
     
  42. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    Atlasing is an issue at the moment, secondary textures aren't combined into an atlas yet. However, we do have plans to do this in the future.

    As for the issue with flipping, this is known, and we are working on a fix.
     
    Last edited: Aug 2, 2019
    Wonka45 likes this.
  43. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    The masks in the material actually should be working, but they are used to mask lighting. If this is what you want try going to your 2d Renderer Data and setting the mask texture channel. If you set the channel to R for example, red values with a value of 1 will be lit and red values of 0 will be unlit.
     
    foxnne and _watcher_ like this.
  44. Ducat

    Ducat

    Joined:
    Jan 13, 2017
    Posts:
    4
    We just found out that Z Scale instantly becomes 0 when you set your scale to Vector2 (-1, 1). That's why Normal Maping is breaking.
     
    Wonka45 and foxnne like this.
  45. GamerXP

    GamerXP

    Joined:
    Mar 22, 2014
    Posts:
    17
    Hello, few question about new Shader Graph's 2D master node:
    1. When using new 2D renderer pipeline, "Scene Color" node don't work. Will this be addressed later or it's intended?
    2. How do I stop shader, created in shader graph, multiplying final color by vertex color? I use this color myself in a different way and it just ruins everything. It should really just stop doing it if there are Vertex Color nodes in the graph.
     
    oscarAbraham likes this.
  46. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    37
    I've been having some issues getting the stencil buffer to work using shader graph and the LWRP with 2D lights. Is it possible to set up a decal system similar to how the lights work? With the lights, you can define which layers are affected and I was wondering if it is possible to have a sprite set up to only affect certain layers so I could get my blood splattered platforms and grounded shadows working correctly again. Attaching a screenshot for the desired effect I'm looking for.
     

    Attached Files:

  47. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,286
    What's the recommended way to go about mixing 2D and 3D assets?

    If we want to have 3D assets in our 2D world, will we be able to light them when using the 2D renderer, or should we use a standard LWRP setup and try to make those lights work with the 2D sprites?
     
    foxnne, BTStone and EvOne like this.
  48. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    46
    I will have to look into this. If you have anything you can send me, that would help me out.


    At the moment I'd suggest you use standard LWRP. However, this is something we will be looking into for the 2D renderer for the future.
     
    Baste likes this.
  49. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,286
    Do you have any kind of estimates for that? We're probably going to want both shadows and 3D assets, but we probably won't start production on that project before 2020 at the earliest, and we might not need 3D before a while into that.

    What we'd specifically want would be 3D assets we could place in the background/foreground, where moving past them would show the asset from different angles.

    Would it be possible to solve that right now with a custom shader?
     
    EvOne likes this.
  50. Brucemax

    Brucemax

    Joined:
    Aug 7, 2019
    Posts:
    2
    I reproduce all steps from youtube video and my game window show only dark blue screen. What I do wrong?
    Upd: For some reason right after set pipline asset to project settings game window start use other camera whitch was on the scene. So resolved
     
    Last edited: Aug 7, 2019