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.
  2. Dismiss Notice

Question Use each channel of a texture to store different UI icons.

Discussion in 'Shader Graph' started by polypixeluk, Mar 23, 2021.

  1. polypixeluk

    polypixeluk

    Joined:
    Jul 18, 2020
    Posts:
    53
    When I've worked on VFX / UI in other engines I've often stored multiple greyscale masks in a single texture file and had a tick box in a material that lets me set which channel the material will use. For example, right now I've got a texture file that has 4 greyscale icons in it, one in each channel (RGBA).

    Is there a way to do with with Unity's Shader Graph? I can see the Channel Mask node, but can't see any way of exposing this to the material.

    Also, I've been trying to use the Sprite graphs, but the non-lit graph doesn't seem to have a separate pin on the master node for transparency. I've tried using the lit graph, but it doesn't seem to accept the R channel as transparency?

    Shader.jpg
     
  2. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    164
    Hi!
    Mask(Mask Texture) in shader graph is use for light blending. That is a bit confusing.
    You can get some information there.:)
    If you want use specific channel as alpha then you should split color and combine that channel as an alpha component. 未命名-2.jpg
     
    polypixeluk likes this.
  3. polypixeluk

    polypixeluk

    Joined:
    Jul 18, 2020
    Posts:
    53
    Thanks! That's the ticket on the transparency problem.

    Can any one tell me if it's possible to parameterize / expose which channel is used so it can be set from within a material?

    Edit:

    It just occurred to me that I could expose a 1Vector for each channel to act a a blend value with a couple of lerp nodes. Is that the best way? Seems very long winded.
     
  4. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    Long-winded, yep...Shader Graph has that problem sometimes ¯\_(ツ)_/¯

    I'm not sure I would call what you suggest the best way, but it would certainly work for your purposes.

    To ease your burden a little: you can copy-paste parameters within the parameter list, if you want to make a bunch of Floats quickly. (Or if you want to copy params from graph to graph!~)
     
    polypixeluk likes this.
  5. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    164
    I prefer use Enum Keywords.
    https://docs.unity3d.com/Packages/com.unity.shadergraph@7.1/manual/Keywords.html
    Mask.png
     
    polypixeluk likes this.
  6. polypixeluk

    polypixeluk

    Joined:
    Jul 18, 2020
    Posts:
    53