Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
Dismiss Notice
Join us now in the Performance Profiling Dev Blitz Day 2023 - Q&A forum where you can connect with our teams behind the Memory and CPU Profilers and the Frame Debugger.

Rim Light in 2D LRP

Discussion in '2019.2 Beta' started by thormond, Jun 29, 2019.

  1. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    On GDC they showed that you can create rim lights through making an outline secondary texture and then somehow setting up a light that only acts on that secondary texture (_MaskTex channel), problem is they don't explain how to setup the light itself to make it only affect the outline. I'm guessing it has something to do with "Light Operation" field which isn't present in our version (main light has Modulate Light, rim light has Additive) or perhaps Import settings of the outline file itself?



    Has anybody managed to reproduce it?
     
  2. Coffein

    Coffein

    Joined:
    Jan 22, 2016
    Posts:
    19
    I don't think this is currently possible as the Mask channel doesn't seem to be working with the 2D LWRP
     
  3. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    What strikes me as weird is that the version they have GDC is 2019.2.0a3, we have an access to 2019.2.0b7, yet we don't have that functionality and they do. Is this something they temporarily disabled?

    We don't have the "Light Operation" field but we have something called "Blend Style" with 3 options that are marked as (Disabled) - anybody knows if it's the same thing?
     
  4. Coffein

    Coffein

    Joined:
    Jan 22, 2016
    Posts:
    19
    You have to define the blend styles in your 2D Renderer asset:
    upload_2019-6-29_12-45-15.png
     
  5. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    Yeah, it seems like it has nothing to do with that and just the mask channel isn't affected by light at all, tried all possible configurations already
     
  6. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,358
    A few steps:
    1) Setup your Blend Styles on the 2D Renderer Asset. For Rim Lights; make a 'Rim Layer' Style
    2) Create a Mask Map that outputs a 'Rim Mask' through your chosen Blend Style Texture Channel
    3) Assign your Mask map to your Sprite Shader's mask input (you can also output the mask texture channel in Shader Graph)
    4) Now create 2D Lights and set them to render on the Blend Style layer of your choise and point to the Target Sorting Layers that your sprite is on.

    I can confirm this all works in 2019.2b5 and LWRP 6.7.1 and should work in any higher version(s).
     
    LeonhardP likes this.
  7. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    I had some difficulties trying to follow that but in the end I managed to reproduce it, here's some additional info that might be useful:
    1) The most important is setting Mask Texture Channel in 2D renderer style, it should be either R, G or B (or One Minus R/G/B if you want inverted rim light)
    2) Mask Map is simply a black-and-white texture where greyscale decides what gets affected by light (white is fully affected, black is not affected at all). You can leave its import settings at defaults (doesn't even need to be a Sprite)
    3) You don't need to assign anything to the shader (i mean you can but that's the hard way and will cause you a lot of overhead) - the easy way is to go to the Sprite Editor -> Secondary Textures, add new texture and name it "_MaskTex" (needs to match that name exactly) and drag your Mask Map in the Texture field (this way you don't need to create a new material for every sprite that needs an outline, you do the same thing for normal maps but the name string for normal maps would be: "_NormalMap"). There's some exceptions where you don't have an access to Secondary Textures (for example with .psb files for 2d animation system)
     
    atrivedi7 likes this.
  8. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,358
    Thats pretty much what I said (Minus the secondary textures part) :D
     
  9. thormond

    thormond

    Joined:
    May 11, 2013
    Posts:
    33
    And yet I started off from choosing "None" and "A" as my Mask Texture Channel for rim layer which surprisingly are the only 2 options that don't yield any result, never lucky :eek:
    (well, they actually do but you end up with something approximating a standard light due to alpha channel being always 1 which makes the entire sprite being evenly affected by light but from the perspective of somebody attempting it for the first time without any back-end knowledge you wouldn't be able to come to this conclusion quickly)
     
    Last edited: Jul 3, 2019