Search Unity

How to change colour of lighted part of a spirite ?

Discussion in '2D' started by PORUSH-UNITY, Apr 15, 2021.

  1. PORUSH-UNITY

    PORUSH-UNITY

    Joined:
    Aug 3, 2013
    Posts:
    3
    Hi, I want to change sprite colour only where it's not being affected by 2d lights, I tried to create a shader using shader graph but couldn't find any node that will be able to do the task. How can I achieve the desired effect ? Any advice will be helpful.



    Thanks.

    PS : I don't have much knowledge of shader graph.
     
    Last edited: Apr 15, 2021
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    It's not clear the effect you want, and how it might differ from using colored lights. For example, blue-shifting the color of a sprite would be possible by simply using a blue-tinted light.

    From your description I don't think a direct implementation is possible because 2D Light data is "behind the scenes" in Shader Graph.

    But please describe in greater detail the effect you want. An illustration may be helpful. Perhaps there's a workaround.
     
    PORUSH-UNITY likes this.
  3. PORUSH-UNITY

    PORUSH-UNITY

    Joined:
    Aug 3, 2013
    Posts:
    3
    @lo
    Hi, I updated my post and added a illustration for more clarity.
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    This can't be done with Shader Graph because lighting is applied after your graph runs, and you have no control over that. It should be possible, however, but you would need to create your own copy of Sprite-Lit-Default and then modify it. This would not be an easy task for a beginner.

    Haven't really thought it through, but perhaps you could accomplish something like what you want with masks, which would be more beginner-friendly. https://docs.unity3d.com/Manual/class-SpriteMask.html
     
    PORUSH-UNITY likes this.
  5. PORUSH-UNITY

    PORUSH-UNITY

    Joined:
    Aug 3, 2013
    Posts:
    3
    Thanks, I might be able to do it with masks. I will do some tests later.
     
  6. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    2021.2.0a16
    You have more options now. What you could do is have an Sprite Unlit shadergraph where you sample from this Light Texture node, then you could interpret that light data as you see fit. For example, if the light node's value is above/below some threshold, then the object is "in the light" or "in the dark" and you can for each apply a different effect.