Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Curious about what's going to be in 2021.1? Have a look at the 2021.1 beta blog post.
    Dismiss Notice
  3. Want to see 2021.1b in action? Sign up for our 2021.1 Beta Webinar on February 25 for a live presentation and a Q&A session with guests from R&D.
    Dismiss Notice

Feature Request Read lights texture in ShaderGraph

Discussion in '2D Experimental Preview' started by ThundThund, Dec 25, 2020.

  1. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    89
    Hi everyone, I've seen that the 2D renderer uses some screen-wide intermediary textures to render the point lights and the shape lights, before they are blended with the rendered objects that are affected by such lights. For example, one of them is called _ShapeLightTexture0. It would be amazing to be able to access such textures in our shaders, it would allow us to achieve a lot of great VFX.
     
    GliderGuy and Lo-renzo like this.
  2. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    You can actually do that today. A few things to pay attention to:

    * You must use the Sprite Unlit material (master node), otherwise symbol redefinition error in shader.
    * You need a light texture property that
    a) references _ShapeLightTexture0-3
    b) doesn't have a default value
    c) isn't Exposed
    d) is sampled in screen space by using the Screen Position node.
     
    GliderGuy likes this.
  3. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    89
    Wow thanks! In the past I tried with a Sprite Lit material and got errors (redefinition of _ShapeLightTexture0), I assumed the light textures were not defined in the Unlit material so I didn't try :D
     
  4. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    89
    Thanks to this I can emulate emissive color, finally.
     
  5. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    89
    Example of emissive:
    -No postprocessing.
    -No Sprite Lit materials.
    -Using custom Unlit shader, reading the light texture, the sprite main texture and a secondary texture as emissive texture.

    Capture.PNG

    EDIT: You can see here how the red global light does not mix with the emissive colors, which is what I wanted.

    Capture2.PNG

    EDIT2: With Bloom:

    Capture3.PNG
     
    Last edited: Jan 6, 2021
    GliderGuy likes this.
  6. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    89
    With this, I can even implement sprite masks that use gradients using the light shapes when rendering some FX.
     
  7. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,994
    Nice one but it still doesnt give us ability to do partly emissive sprite?
     
  8. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    89
    Yes it does. You have the main sprite texture and the secondary emissive texture. Then you just multiply the main color by the light texture when the emissive texture is transparent and use the main color without multiplying it is not.
     
  9. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,994
    So I have to change entire game's rendering shader to this "unlit" shader that manually "relight" them? :D
     
  10. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    89
    Yes! :rolleyes: In my case it was not that bad since 95% of sprites used the same base shader. It is not a solution, it's a temporary workaround.
     
  11. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,994
    Yeah, it beats me why this was not implemented the first time. It is the first thing that I would think of if I ever come up with any rendering pipeline..
     
    ThundThund likes this.
  12. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    600
    Is it possible to write directly to _ShapeLightTexture? I think I could eliminate 90% of my Light2Ds and do some really funky stuff.

    edit: looks possible... requires digging into the 2d renderer... not tried yet
     
    Last edited: Jan 11, 2021
    GliderGuy likes this.
unityunity