Search Unity

Color Mask creating an outline around black area when selecting grey area

Discussion in 'Shaders' started by Loquinette, Aug 16, 2018.

  1. Loquinette

    Loquinette

    Joined:
    Feb 13, 2014
    Posts:
    12
    Hey guys,

    I'm using the color mask node in the shader graph and I can't figure out a strange behaviour.
    On my alpha channel there is a black and a grey (128-128-128) areas and I want to isolate the gray area.

    The issue here is that even if my black area is drawn with the rectangle selection without any gradient whatsoever, the result of the color mask returns a thin line around it.
    You can see the settings I'm using, a range of 0.3 a fuzziness of 0.2 and the value of the color in the "Mask Color" section is 0.5-0.5-0.5

    Here's how it looks :



    If I use "Point (No filter)" in the filter Mode of the texture it works, but I can't use that because the texture (not visible here) will then look weird.

    Thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Working as intended.

    When the texture is using the default bilinear sampling, it’s blending between pixel colors to smooth out the image. The result is that if you have a black and white pixel next to each other, a gradient going from black to white will be what is sampled by the shader. If you then use a color mask node to pick a grey value, that value is guaranteed to appear at some point in that gradient between the black and white pixels.

    So, the color mask node is doing exactly what you’re asking it to do. It’s also why point sampling solves the issue as it doesn’t create that gradient.

    The usual solution is to use multiple color channels for different masks instead of trying to pack them into one texture channel. The alternative would be use in shader point sampling and recreate the bilinear filtering by doing the color mask on 4 texel samples at a time, then lerp between the results. I have no idea how to do that with Shader Graph, though I imagine it’s possible.
     
  3. Loquinette

    Loquinette

    Joined:
    Feb 13, 2014
    Posts:
    12
    Oh ok, that make sense now.
    Thanks a lot for the answer. I'll try to find a way in shader graph or as you say, use an other texture taged as no filter and store 3 of these in the 3 channels, that me be ok in my case because I'll have to store more than one of these.