Search Unity

ColorMask override impossible in surface shader

Discussion in 'Shaders' started by brianchasalow, Jan 19, 2019.

  1. brianchasalow

    brianchasalow

    Joined:
    Jun 3, 2010
    Posts:
    208
    While working on a project recently, I wanted to change the ColorMask in a surface shader. I recall this being an issue several years ago and assumed it would have been fixed by now. Turns out, this is not the case. You can theoretically view compiled / generated code from a surface shader, and then save that with a modified ColorMask, but that’s not really usable.

    I couldn’t find much info on the forums about this particular issue. Curious if anyone else has run into this, or if a graphics engineer from Unity would like to comment on it. Thanks!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    Surface shaders do a lot of stuff that can't be overridden. Unfortunately it's just the nature of surface shaders. I generally avoid using them these days for that reason, or just assume I'm using a surface shader to do an initial "layout" and that I'll be using the modified generated code.
     
  3. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    That's genius! For some reason, I had never thought about using generated code of surface shader. Now it's easy peasy to set proper ColorMask. Thanks!

    For anyone else: You can view the generated code of surface shader, copy it, and paste in a new shader file with proper name.
    Select your surface shader in Project View. In the inspector you should have this:
    upload_2022-8-1_19-13-52.png