Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    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. Grafos

    Grafos

    Joined:
    Aug 30, 2011
    Posts:
    226
    Any updates on the light shafts?
     
  2. WonkyDonky

    WonkyDonky

    Joined:
    Aug 24, 2014
    Posts:
    27
    Does Normal Maps work with sprite atlases now?
    +
    Any timeframe on full release?
     
  3. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Writing to normal buffer does not respect depth buffer! Please fix this!
     
    E_Urban likes this.
  4. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    We should be able to choose the light buffer and shadow buffer (if this also exist) sampling type. For pixel art style, we would very much like to have pixel perfect 1:1 pixel ratio to what is set on the main camera.

    We also want to have the shadows's intensity to be controlled not only by the light but also by the shadow caster as well. This is because we want to control the intensity of the shadow, but at the same time we need ability to block light completely so we can control the leaking to the other side of the wall for example.
     
    Last edited: Jul 6, 2020
    Ruskul and GliderGuy like this.
  5. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Also when you are drawing shadow, it seems like the objects that are outside of range of particular shadow casting light is also drawn into consideration.. I am looking at the frame buffer, and draw call increased whooping number of multiples when I started using shadow. I can understand some more draw call is needed , but most of the objects that are well outside the range of the light is still casting shadow for some reason. This has to be a bug? Maybe this is kind of thing that Unity is talking about to fix and currently working on?
     
    GliderGuy likes this.
  6. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    67
    Hello!

    I've been trying out your lighting-features and they are AMAZING.Thank you for making such wonderful tools.

    I saw the Unity tutorial on how to make "light shine through leafs". In it you take theses sprites:
    and make Sprite-Lights of them and make beautiful light-patches on grass:



    Trying to make an 'inverse' cloud-shadow effect:
    I thought perhaps I could do reverse effect, where I make a reverse sprite to make "shadow patches on grass" that resemble clouds passing overhead. I have done this and the sprite looks like this:

    (it's like an inverse version of your light-patches sprite). The effect that I get with this on a Sprite Light 2D is beautiful, see here in this video:


    However, with this solution, as you can see in the video, one always has to consider how to handle the edges of the where the "Sprite Light 2D"-sprite ends. You can see this edge of sudden light/dark appearing around the sprite when the "cloud" moves downward in the video above. Due to this the Light Sprite 2D becomes difficult to use here and probably for other similar purposes.

    My Question:
    Because of this I am wondering if you are planning on adding something like a "Shadow Sprite 2D" (much like your "Shadow Caster 2D" script)? What I mean is a feature where a sprite becomes a 2D-shadow (unlike your wonderful Shadow Caster 2D that casts a shadow). And if not, would you consider it?

    If it existed for example I, and others in a similar position, could simply use sprite like this:

    And use it to become/"cast" a shadow in the world.

    I think it would be a very powerful tool for developers and enable even more flexibility (especially when you've created such a powerful system for manipulating light.)

    Thank you so much in advance!
    Hulda
     
    Last edited: Jul 9, 2020
    Storm4_ likes this.
  7. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    895
    Some people accomplish an effect like this by putting a screen-sized sprite in front of the camera with a shader that animates the clouds so they swirl in and out. The shader takes into account the worldspace position so that as the camera moves about the position changes so the swirling clouds appear to have a real worldspace position independent of being of the sprite, which stays locked in front of the camera. Other weather effects, like rain, can be done in a similar way. As someone who didn't gravitate to shaders as a solution because of their unfamiliarity, Shader Graph makes stuff like this way easier than it used to be. Might be worth investing some time in.
     
    HuldaGnodima likes this.
  8. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    195
    Is there an update on the state of the _CameraOpaqueTexture? If I'm not mistaken it's still broken in then 2D renderer :/
     
  9. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    Unfortunately, you are not mistaken. It's still making its way to the top of the list of things we need to do.
     
  10. Cambesa

    Cambesa

    Joined:
    Jun 6, 2011
    Posts:
    113
    Make your own shader based on the Sprite-Lit-Default and in every pass, multiply the value by the _Color property before returning.
     
  11. SlimeProphet

    SlimeProphet

    Joined:
    Sep 30, 2019
    Posts:
    50
    Maybe change the title of this thread since there's no more LWRP...
     
    rustum likes this.
  12. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    144
  13. theindielawyer

    theindielawyer

    Joined:
    Mar 25, 2016
    Posts:
    21
    Hey! Been using the lights for a while and really enjoying them and the wider 2D features.

    Something recently prompted me to go back and look at my tilemaps which have secondary normal textures applied. When I rotate them in the tilemap editor the normal maps don't rotate alongside the tile's sprites, which I gather is because the normals are calculated from UVs, so they don't (and shouldn't) line up if rotated. Lazy past me just generated all 4 sides of the tilemap which is a fairly inefficient way of doing it but worked.

    I wondered if anyone could point me in the right direction for how to go about doing this for future projects (this has been most useful). Seems like it might be a job for a custom shader?
     
  14. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    I think this is a bug and should be reported.
     
  15. WonkyDonky

    WonkyDonky

    Joined:
    Aug 24, 2014
    Posts:
    27
    @rustum @Chris_Chu

    Any timeframe on Normal Maps working with sprite atlases?

    + Target sorting layers available on script?
     
  16. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    This is already working but you need to be using Unity 2020.2 alpha. I am not sure if it works with 2020.1
    It will be cool to have some official stand on this, which version of Unity and URP it is supported.
     
  17. WonkyDonky

    WonkyDonky

    Joined:
    Aug 24, 2014
    Posts:
    27
    Do you mean normal maps or target sorting layers or both?
     
  18. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    I'll check it out, because if it's not working its a bug. If it is working, I'll try and track down what version of unity/urp its working in.

    @Venkify
     
  19. adamgemerson

    adamgemerson

    Joined:
    Aug 4, 2020
    Posts:
    1
    Hey there! I was wondering if there is anyway to achieve filtering and layer masking within the 2DRenderer? If not, are there plans to include render features in the future?

    Thanks!
     
  20. Centribo

    Centribo

    Joined:
    Nov 3, 2012
    Posts:
    4
    Hi, A project I'm working on is using Universal RP 7.3.1 and Unity version 2019.4.1f1.
    I've been having trouble trying to get a custom image effect shader working in the 2D rendering pipeline. I'm trying to do a cut-out lighting effect similar to this.

    My plan of attack was to render all light sprites to a render texture, then on another camera render all sprites as unlit. There would then be an image effect shader that combines these two results using some blend. Unfortunately, I can't seem to even get a basic custom image effect shader working at any capacity, even something like making everything grayscale. Does the 2D rendering pipeline not currently support custom image effects, or is there some resource out there that I can try to get this to work? I've tried the following:
     
  21. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    For legacy renderer, we were able to choose between different HDR buffer format to save some performance on lower capable hardware such as mobile or Switch. What is the default HDR buffer format used right now and is there way to change it if it is using F16 format?
     
  22. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    Right now these formats are specified by the Universal RP Asst. The default HDR format appears to be GraphicsFormat.B10G11R11_UFloatPack32 if alpha is not needed, and GraphicsFormat.R16G16B16A16_SFloat if it is. If these formats are not supported then it falls back to the platform's default HDR format.

    To answer the second part of your question, it doesn't look like there is a way to change this.
     
  23. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Thanks for the info. At least I know it now. Hopefully we are able to set the format as we need. How can we tell renderer that we need to be able to write to the alpha?
     
  24. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    It is controlled by Graphics.preserveFramebufferAlpha which reads the value from the player settings.
     
  25. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Ok, so Graphics.preserveFramebufferAlpha = true means do not write to alpha right? Making format GraphicsFormat.B10G11R11_UFloatPack32 and if false making GraphicsFormat.R16G16B16A16_SFloat
     
  26. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Forgive me if I am asking stupid question, but I cant find this option about Graphics.preserveFramebufferAlpha anywhere in the player settings.

    Graphics settings has :

    upload_2020-8-11_11-54-46.png

    And there is nothing that I can tell on URP Pipeline Asset or Renderer Asset...

    Can you tell us exactly how / where to find this option please?
     
  27. theindielawyer

    theindielawyer

    Joined:
    Mar 25, 2016
    Posts:
    21
    Thanks, much appreciated!
     
  28. PolyGryph

    PolyGryph

    Joined:
    Jan 22, 2018
    Posts:
    9
    Hey there! I just added the 2D lighting to my game, and I'm trying to write a cel/toon shader to light my sprites. However I can't seem to access lighting information in shader graph. Is this currently possible?
     
    GliderGuy likes this.
  29. jeraldtapz_unity

    jeraldtapz_unity

    Joined:
    Feb 3, 2020
    Posts:
    3
    Is there any update on this?
     
  30. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    https://docs.unity3d.com/2019.1/Documentation/ScriptReference/Graphics-preserveFramebufferAlpha.html
    https://forum.unity.com/threads/wha...r-rendering-unity-on-top-of-native-ui.616651/
     
  31. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    I'm sorry, I still don't have an update. Since there seem to be a number of people interested in this I'll try and post an update when I have one.
     
  32. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Ok the above thread tells me that it is mobile only option. Desktop and Console platform does not even show this option in the player setting. Since I am actually interested with Desktop and Console platforms, I am curious to know and can assume that Graphics.preserveFramebufferAlpha is always set to false for console and desktop build? forcing HDR format of GraphicsFormat.B10G11R11_UFloatPack32 at all times without any choice?
     
  33. PolyGryph

    PolyGryph

    Joined:
    Jan 22, 2018
    Posts:
    9
    Hey there, would just like some confirmation on whether you can interact with 2D lighting information in shader graph or the ability to do so is in the works.
     
  34. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    You can interact with the lighting information in shader graph.

    There are 4 light buffers that correspond to the light buffers of the blending styles. They are global textures and named:

    _ShapeLightTexture0
    _ShapeLightTexture1
    _ShapeLightTexture2
    _ShapeLightTexture3

    If you create a texture2d on the blackboard and use those names in the ref field, they will reference the light buffers.

    There may be changes to these names or the way lights work as the 2D Renderer is still experimental.
     
    Last edited: Aug 15, 2020
    AzureMasters, PolyGryph and Lo-renzo like this.
  35. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    Yes. If you need a different format, you might want to try and bring it up in https://forum.unity.com/forums/universal-render-pipeline.383/

    This is functionality built-in to Universal RP and not specific to the 2D renderer.
     
  36. PolyGryph

    PolyGryph

    Joined:
    Jan 22, 2018
    Posts:
    9
    Thanks Chris! Is there currently any documentation on how this works? I cant seem to find anything in the Unity Documentation.
     
    Last edited: Aug 16, 2020
  37. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    490
    SpriteAtlas support for Secondary Textures is added in 2020.2. Thanks.
     
  38. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    895
    Wonderful to hear! Any chance you can support runtime Sprite Atlas generation for mods / content from web? Even if there's a reduced feature set, it would be very helpful in all kinds of scenarios.
     
    Last edited: Aug 20, 2020
  39. PolyGryph

    PolyGryph

    Joined:
    Jan 22, 2018
    Posts:
    9
    I've looked into the shader code, and it appears that normal map interaction happens on the light2D shader using some sort of normal map shared between sprites rather than light direction data being used on the object (unless I've misread what is happening, fairly new to shader code).

    If I'm correct, this means that I could not, for instance, have an object use its normal map for toon shading and another use regular normal shading, nor control color for shaded areas separately without also changing it for every other object.
     
  40. Joshdbb

    Joshdbb

    Joined:
    Oct 28, 2014
    Posts:
    47
  41. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    We don't have any docs or shadergraph samples for this at the moment. We are sorting some things out with the way light buffers work, I think when the changes are online, we can add a shadergraph sample or docs.

    Were you able to get what you wanted working?
     
  42. PolyGryph

    PolyGryph

    Joined:
    Jan 22, 2018
    Posts:
    9
    I dont think what I would like to do is possible yet without some heavy modification that is likely beyond my skill. When I looked into the shader code it looked like normal maps (and maybe light maps too) are processed on the light rather than the sprite. So if I wanted to change the way a mapped sprite is affected by the light, it would affect all sprites. Meaning, for example, I couldn't have one sprite cel shaded and another sprite normal shaded, or have light masks affect different sprites differently.

    I could just be misinterpreting how the shader code works though, since I am fairly new to it.

    Perhaps a solution could be an option to have the light directions render to something like a _ShapeLightNormals[index] texture similar to how the light buffer is rendered, and maybe stick attenuation in the alpha channel of the light buffer (if that's possible since it seems like the alpha channel is unused) so that we can perform shading calculations on the sprite?
     
    GliderGuy likes this.
  43. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Can you at least let us know "guesstimate" on when this will happen? We would like more information on schedules about 2DRenderer development.
     
    Lo-renzo likes this.
  44. Joshdbb

    Joshdbb

    Joined:
    Oct 28, 2014
    Posts:
    47
    I'm having issues with the lighting on 2D sprites with normal maps flickering as the camera moves.

    Here are two zoomed in images. Both same gameobject/sprite/normal but camera in different places.

    LightingIssueGravestone1.PNG LightingIssueGravestone2.PNG

    As you can see the lighting on the 'lip' changes as the camera moves. This causes a flickering effect when the camera is in motion.

    I also get some flickering on the outside edges of the sprite.

    I guess this is caused by the normal map lining up with the pixels in different ways depending on the camera position and so sometimes the normal colour gets blended with neighbouring colours.

    This is probably only a real issue when you have hard edges in your normal map. Not having hard edges is a pretty big limitation though.

    Has anyone had any experience with this issue? Maybe there is something I can do to fix it?
     

    Attached Files:

  45. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    I would first vheck two things.

    1. Pixel perfect placement of sprite.
    2. Pixel perfect placement of camea.

    And maybe also check the light buffer size to be 1 so it matches your screen size.
     
  46. Joshdbb

    Joshdbb

    Joined:
    Oct 28, 2014
    Posts:
    47
    Where do I find the light buffer size?
     
  47. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    477
    Not sure which thread to ask for this, but each of our scenes has a global light in it and there are multiple situations where we are loading up multiple scenes and we're receiving the error from Light2D.cs:427

    Code (CSharp):
    1. Debug.LogError("More than one global light on layer " + SortingLayer.IDToName(sortingLayer) + " for light blend style index " + m_BlendStyleIndex);
    I get why it's there, but whenever, we're doing processing that requires multiple scenes to be loaded up that error shows up in the log. Is there anyways I could ask for a static bool added to the codebase to disable this check? Or maybe have a checkbox on the 2D renderer settings that we can turn off for our project? I can add it myself, but I don't particularly want to have to update everytime we update the URP.
     
    wlwl2 likes this.
  48. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,254
    Does _CameraOpaqueTexture work with 2DRenderer?
     
  49. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    I get why you need this. Let me look into this and I'll get back to you.
     
    wlwl2 likes this.
  50. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    212
    Not at the moment.

    Let me ask about what I can talk about.
     
unityunity