Search Unity

  1. The 2021.2 beta is now available. To find out what's new, have a look at our 2021.2 beta blog post.
    Dismiss Notice
  2. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  3. Dismiss Notice

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

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

  1. berkza

    berkza

    Joined:
    Oct 9, 2018
    Posts:
    3
    Hi! Is it planned for the 2D renderer to support "custom features" like the foward renderer does? I found this post from Erdroy https://forum.unity.com/threads/urp-2d-renderer-custom-feature.778946/ and was wondering if it was recommended to follow his steps and customize the renderer, because his PR seems to be in low priority. Thanks in advance, any reply will be helpfull.
     
    rboerdijk likes this.
  2. ShinKazuo

    ShinKazuo

    Joined:
    Oct 28, 2014
    Posts:
    12
    Hey friends, I have a question about the shadow caster 2D script, didn't find the answer through the
    Currently I have a player character that is a circle but when it attacks it turns into an ellipse. Is there a way for the shadow to be created relative to the sprite shape instead of manually editing the shape in the inspector? Otherwise the shadow will always be created using the idle character shape even when he's attacking, which is kinda weird.
     
    elZach and RealoftRU like this.
  3. CoraBlue

    CoraBlue

    Joined:
    Nov 16, 2017
    Posts:
    5
    I just wanna send a huge thank you to the team at Unity for this feature. This is actually insane. I really struggled for a really compelling reason to use LWRP/URP before this. This is literally a game changer.

    For small-time devs especially, we don't really have the luxury or frankly the knowledge in some cases to be worrying about a lighting system in a 2D game. Asset store packages can be a pain to implement and who knows how long support will last anyway? This is an honest reflection of only 2 hours of porting, half of which was hand-painting normal maps!

    https://imgur.com/a/gzfMQ64

    I went from throwing an additive material over the scene and calling it good enough to mindblowing results and the speed at which I did it speaks to how friendly you've made this system. You all deserve a freaking medal.

    EDIT: Very much looking forward to sprite atlas support in 20.2+ whenever that comes.
     
    Last edited: Feb 11, 2020
  4. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    Is there shadow caster support for tilemap?
     
    elZach likes this.
  5. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I replied in the original post. In a nutshell, we want to enable user customization only after we get the 2D Renderer ready for production.
     
    berkza likes this.
  6. berkza

    berkza

    Joined:
    Oct 9, 2018
    Posts:
    3
    Thank for your response yuanxing_cai! 100% understandable and it gives me some insight on what to do. Just to let you know, I currently customized the renderer as Erdroy did, and it's working in my project. In the future if you need some testing in this matter I'll be here :)
    Thanks again!
     
  7. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    @yuanxing_cai , can you let us know about shadow cast support for the tilemap please?
     
  8. alex174

    alex174

    Joined:
    Mar 19, 2019
    Posts:
    10
    Hello!
    On the 13th, the URP 7.2.1 update was released.
    When updating, the console displays a warning:
    "There are inconsistent line endings in the 'Packages / com.unity.render-pipelines.universal / Editor / AssetPostProcessors / FBXArnoldSurfaceMaterialDescriptionPreprocessor.cs' script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands."

    Why does version 7.1.8 have a status of "verified"?

    And further:
    On February 5th, Chris wrote that he fixed a problem with the color parameter in the Sprite Shape Renderer. This is the second URP update since then, but the fix is still not included.
    I fixed it manually, but after closing the project, the changes are not saved.
    When will this small fix be included in the URP update?
    Thanks in advance!
     
    elZach likes this.
  9. berkza

    berkza

    Joined:
    Oct 9, 2018
    Posts:
    3
    Alex! In the meantime if you need to keep the changes I followed https://github.com/Unity-Technologies/ScriptableRenderPipeline#how-to-use-the-latest-version but instead of cloning the repo made a local copy of the package. Hope it helps.
     
  10. CoraBlue

    CoraBlue

    Joined:
    Nov 16, 2017
    Posts:
    5
    After tinkering with this a couple days I do have some minor issues.Without sprite atlas support (for now) am I stuck with this?



    The other solution would be pixel snap but I notice that the sprite shader in URP does not have pixel snap. Will the final version of the shader have pixel snap?

    Also will point out that at resolutions this small the lights themselves also subpixel drift a bit, which looks a bit off.

    Lastly it looks as if you're disabling lights that are outside the camera view for performance reasons, but this doesn't play well with 'offset' in freeform lights if you're trying to create a fade (a sunbeam effect or something). The light disappears well before the offset light is offscreen.
     
  11. MrPaparoz

    MrPaparoz

    Joined:
    Apr 14, 2018
    Posts:
    155
    Any highly optimistic ETA on this? At least a version target, maybe 2019 LTS?
     
  12. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    191
    When we are out of experimental we should support all the features of the legacy sprite shader/renderer.

    As for the offset issue, thanks for finding this. This sounds like a bug and we will try and fix this when we can.
     
  13. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    191
    There were reasons it didn't make it into 7.2.1. The color fix will hopefully be in the next version of Universal
     
    Lars-Steenhoff likes this.
  14. alex174

    alex174

    Joined:
    Mar 19, 2019
    Posts:
    10
    Thanks.
    Sorry for the importunity. Will wait.

    Thanks for the advice! I thought about it, but maybe I'll wait for the update.
    Did you put a copy of the package in the asset folder?
     
  15. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    Any respond from Unity about shadow support for the tilemap?
     
    elZach likes this.
  16. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    191
    You can make this work, there has been some discussion about this in the forums, so you might want to poke around and see if you can find a solution that will work for you.

    Right now I will say the support for tilemap isn't the best it could be. There will be work done on this in the future, but I'm not sure when.
     
  17. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Unfortunately we don't have an ETA yet. It's very unlikely to be 2019 LTS.
     
  18. MrPaparoz

    MrPaparoz

    Joined:
    Apr 14, 2018
    Posts:
    155
    Thanks for heads up. Good luck with progression. Please keep us updated about what's coming.
     
  19. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    136
  20. Generic_Username_12345

    Generic_Username_12345

    Joined:
    Jul 18, 2017
    Posts:
    3
    Did you find the solution?
    I have the same problem with lights, that are not smooth...
     
  21. luoweihong

    luoweihong

    Joined:
    May 27, 2019
    Posts:
    13
    how can I get that effect in LWRP 2d Render? all point light Pre-generated on a mask map in LWRP,

    dose it have some way to get the point light infomation in shader ? the target sortinglayer in the inspector in my game is not a good way to use..because there are many gameobject will be dynamic spawn...

     
  22. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    The shadow in that image is not generated by the light. It's just a separate sprite rendered on the ground. And it uses normal map as well.
     
  23. luoweihong

    luoweihong

    Joined:
    May 27, 2019
    Posts:
    13
    i focus on the light...not the shadow, because in the lwrp render i can't get the light position, so i don know how to make this lights up effect
     
  24. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    I am not entirely sure, but URP (LWRP) 2d renderer component is still early stage.. It is still missing some number of important features to be honest so I would not bet my life on it.

    The above image is achieved by using normal "legacy" renderer pipeline. I think it was deferred rendering. So currently, your best bet is to use that rendering pipeline. Otherwise, you need to track the light position yourself and then update shader parameters manually.
     
  25. MrPaparoz

    MrPaparoz

    Joined:
    Apr 14, 2018
    Posts:
    155
    It's a prototype. There are more feature complete solutions on Asset Store that I have one of. Negative side is they don't support SRP yet and in my case it means no more shaders (for I don't understand how to script them).

    Asset I have (Smart Lighting 2D is the name), have this feature I think. Check it out if you are going for production in a short while. btw I am not author of that asset, just trying to heads up.
     
  26. luoweihong

    luoweihong

    Joined:
    May 27, 2019
    Posts:
    13
    yeah.. maybe i can't use lwrp to do that..
     
  27. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    Ok, Here is something that I am struggling to understand.

    upload_2020-5-2_22-40-32.png

    This is a frame profile capture of my scene. I have two cameras but things to notice here is that there are multiple batches of 2d lights rendering passes... All my light settings are the same as far as the masking layers goes and I am only using one light blend style.

    But seeing that there are multiple batches of 2d lights being rendered, it seems like it is doing something else than what I expected it to do.. it is rendering the same 2d lights over and over again. I think it has something to do with the number of light's layer mask.. So if I have 4 layers and light affects all 4 layers then it renders the same light 4 times.

    If this is true, I can understand the reason behind it a bit because it wants to "mask" the layer per lights... BUT... from performance point of view, this is surely is not a very ideal way to do it? We should surly only render lights once and then reuse it to render the layers instead?

    Anyone? From Unity to shine some lights on this? If what I think is true, then having multiple layers to organize the scene is pretty much not possible ( not practical )

    Also, this will "probably" cripple performance on mobile. or console such as Switch...
     
  28. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    65
    Hi once again @Chris_Chu

    Is there any chance of knowing more or less when this will be implemented? My project has been waiting for it for half a year now, based on your answer we decided to leave everything dependant on _CameraOpaqueTexture on hold but as the release date approaches we are unsure of if we need to try to find alternatives or Unity will fix it anytime soon
     
    jeraldtapz_unity likes this.
  29. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    191
    I'm really sorry about that. Performance has become the priority with other features, unfortunately, taking a backseat. .

    I still feel that _CameraOpaqueTexture is important as it feels broken at the moment, but I don't have a timeline that I can give you as to when it will be in.
     
    rboerdijk likes this.
  30. Kribzii

    Kribzii

    Joined:
    Sep 2, 2019
    Posts:
    3
    Hi,

    Does anyone know how to BLOCK point light from passing through certain objects with this package?

    I want the point light to not pass certain objects (Shadow Intensity set to 1.0).
    Other objects should have a Shadow Intensity of 0.5 or something..

    Can someone point me in the right direction?
     
  31. mbitzos

    mbitzos

    Joined:
    Jun 8, 2018
    Posts:
    17
    Does anyone know if there is a way for 2D lights to ignore a specific sprite I have in my scene? I can't use the "Target Sorting Layers" because it would require putting it on a different sorting layer which would break sorting in my case.

    To give context I am making a top down game (not birds eye perspective) and I am trying to simulate a room with a light. but the outside of the room's wall that is facing the camera is having the light shone on it which isn't realistic in how a real 3D room would work. I can't put the wall on a separate sorting laying because the other objects have to go in front of the wall at some point (player etc.)

    Essentially what I would benefit from would be to be able to specify the culling mask layer for the 2D lights that the current Light component has. If its not possible I think that would be a really good feature to include in the future!

    Any help is appreciated
     
    Last edited: May 10, 2020
  32. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    191
    Are you talking about all lights? Or a select few? If you are talking about all lights you can always use unlit sprites.

    If you are talking about selected lights, I don't think there would be a good way to do this because the lighting has already been calculated for a layer before the sprites are drawn.
     
  33. mbitzos

    mbitzos

    Joined:
    Jun 8, 2018
    Posts:
    17
    Unfortunately I am talking about only selected lights as using unlit sprites is not an option. Is there any reason why the 2D Lights only target sorting layers and not regular game object layers as well?
     
  34. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    Does URP 2D Renderer support Secondary Textures? If so can I use any custom name for the shader?

    Also does tilemaprenderer supports secondary texture? If not, it is pretty much useless because most of the time tilemap + normal sprite combination is used in the game.
     
    elZach likes this.
  35. DatThax

    DatThax

    Joined:
    Jun 18, 2019
    Posts:
    10
    This is still happening in URP Version 9.0.0-preview.14.

    Any update on this issue @Chris_Chu ? It makes getting good lighting for our game really hard.
    I also reported this bug on fogbugz with case number 1193870
     
  36. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    69
    Is there any plan to add soft shadows and light widths to the 2d lights? Basically penumbras.

    So many of the 2d light assets packages supported penumbras, but most aren't supported anymore because... you know, its not profitable now that unity has a solution.

    The other hope I had is that we could access the "light" layer(s) directly and influence what they do. I would very much like to render a set of lights and modify the light so that it is banded or cell shaded and then apply it.
     
  37. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    We really need to have more , better lighting node for Sprite in 2DRenderer. Especially a emission channel.
    Right now, everything is affected by the light so we can't really do , for example hit flash properly.
     
  38. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    69
    Yes, we really do,

    I have a solution for you (unity's solution found from a video they released), and an alternative more powerful solution of my own devising:

    Currently, you can specify a custom light blend mode and base it on a mask. Basically, if you want an object to flash a particular color in response to a particular light, you can do. The light just has to use one of the blending modes you set up in your 2d renderer asset. The down side to this method is that anything with the same mask, in the same layer, will also respond to the light, meaning you have to use shader graph to create a material that changes its mask on and off. There are still severe limits, for example, if I want to create an emission color instead of using the diffuse map or light color, I can't.

    So, I prefer a clever workaround that kind sucks, but here it is: You can create transparent sprites. When two sprites are alpha blended you get an average of their colors, basically. But what we want is additive blending for the emissive sprite, which can be done with some clever alpha blending.

    If you double the intesity of lights and layer up sprites with %50 alpha... when they lerp the result is the same as adding them, had they been lit normally. You have to put the emmisive sprite ontop of the diffuse sprite and each in their own sorting layer, but this way they can be affected by different lights, etc...

    Using this method, I currently have a space scene where I have sss, fresnel glow, specular highlights, and emission on all my sprites... with of course 2d lights. The problem is that I need a seperate light and sorting layer for each category, and every sprite object is then layered together, so overdraw is pretty high.... but I'm still getting 500fps so, meh, whatever.
     
  39. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    191
    I will be on it in one to two weeks. I'm sorry this is taking so long I'm trying to finish up some work that needs to get into the editor before a particular deadline.
     
  40. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    191
    Secondary textures were actually made with the 2D renderer in mind. The names are specific if you want to use normal maps and mask textures, however if you have your own shader you can use whatever name you want.

    There are some docs on using secondary textures here
    https://docs.unity3d.com/Packages/c...s.universal@9.0/manual/SecondaryTextures.html
     
  41. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    This seems too hackish and not flexible enough, not cost effective to just do a simple emission channel...
     
  42. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    Can we please have an emission channel on the lighting side so we can add secondary texture for the emission?
     
  43. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    Also, does 2DRenderer Tilemap Renderer supports Secondary texture? Or it only works with Sprite Renderer?
     
  44. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    69
    Unity's method isn't flexible. You are stuck with the colors of the lights, and layering issues arise. My method, is 100% flexible. Objects pretty much have to all be prototypes (which I admit mine are anyway, so the I could bear the cost), but you are right. A simple emission ch would be most lovely.

    Objectively, I can't see why we don't have it.
     
  45. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    69
    Unfortunately, using secondary textures and your own shader graph still doesn't allow for proper emission. In the examples from unity, they use additive light blending, which, if you you have a stack of sprites all needing emission, the lights stack, unless you layer it and light them separately, which is not scalable. For a single object overlapping itself n times, you need n sorting layers.

    Take the following example:

    I have a bioluminescent plant. It emmits a soft blue glow in spots and has purple subsurface scattering emitting around the glow spots. The diffuse map, however is a grey. If we had an emission ch, I could simply create a secondary texture and plug it in. But as it stands, I have to find a way to add the emission ch color to the diffuse color. But here is the thing. If there is no light shining on the plant, it shouldn't have any of its diffuse color contributing to the scene.

    Unity's way suggest I create mask ch, set up an additive light to respond to that mask ch. Now, this is fine, if you only have one object contributing an emission map. Here is why. an additive light, will only contribute the color of the light to the scene. This means in order to get a colored emission in a scene with no regular lights, I have to have my additive light set to the color of my emission. This falls apart when I have two objects overlapping that have different emission colors. Which means, I need to either use a multiply light instead of additive (so I can get the color from the shader), or I have to to have n sorting layers (refer to explanation above).

    Basically, If I use a multiply light to act only on the emission mask ch, then I have the problem that I can't calculate how much diffuse color should be added to the color output because I have no way of knowing if my object is lit by a regular light or not.

    Basically, its highly impractical to have one light operate on one texture map, and then add that texture map to another separately lit one. As I mentioned in a previous post, I have an game with glowing plants, that have a surface color different than emission color, that have specular highlights, and subsurface scattering. I achieved this all by layering up multiple sprites set to 50% transperancy, sitting ontop of each other, in specific sorting layers, affected each by specific lights with their respective intensities doubled, quadrupled, or whatever as calculated in order to get the effect of adding the sprites together, even though they are being alpha blended.

    Long story short, Every light in my game has to be 4 lights, and every object has to be layered up from multiple sprites. This is the only work around I have found.


    TLDR. If I could access 2d light data in 2d shaders, I would be golden. But I can't.

    Adding an emission ch would help fix part of the issue, and would simplify my hack of a workaround. Seriously though. We need 2d light data in shader graph and an emission ch.
     
    s-korovkin likes this.
  46. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    69
    Also, quick question, I already asked, sorry it am being impatient...

    Is there a plan to add pnumbras / soft shaders to the light system?

     
  47. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    69
    Also, can we have it so the shadow caster shape can be pulled from the 2d collider. Its kind of silly to have to enter the same shape more than once.
     
  48. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,177
    I have questions about SRP batching ( or just draw call batching in general) in 2Drenderer. To my dismay, I have not seen any SRP batching happening for my scene, where I pretty much use the same shader for most of the objects. The shader itself is made using Shader Graph, using the default ( and only ) Sprite Lit Master node.

    Any information about SRP, or on how any batching works for 2D Renderer? I am familiar with other types of batching techniques from legacy rendering era. I am pretty sure my scene had a lot of SRP batching on just normal URP, but moving to 2DRenderer, it all seems to not work anymore. :(
     
  49. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    69
    Further expanding on the need for an emmision ch and texture in the 2d master node:

    My hack arounds are ok and all with basic sprites.... until you start using things like sprite shapes or 2d animated rigs. Then things start to really suck.
     
  50. Alieldin

    Alieldin

    Joined:
    Dec 24, 2016
    Posts:
    2
    Any estimate as to when _CameraOpaqueTexture (or the Scene Color node) will work with the 2D renderer?

    Also, is there any way to fade 2D shadows based on distance, right now shadows generated from a Shadow Caster have the same transparency all the way until they end with the light. Any way to make them fade over distance from the light source? Thank you!
     
    jeraldtapz_unity likes this.
unityunity