Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Stencil Op/Comparison Values

Discussion in 'Documentation' started by Giometric, Oct 20, 2015.

  1. Giometric


    Dec 20, 2011
    The ShaderLab stencil documentation lists what the available stencil operations and comparison functions are, but does not mention that these correspond to various integer values (the UI shaders use Float variables that appear to get set by the masks/etc at runtime to take advantage of this). It would be nice if these were listed in the docs along with the values. The Stencil Operations list seems to match up, but the Comparison Functions does not. I couldn't find a list of the latter anywhere online, so I messed about for a bit and came up with one (hopefully it doesn't turn out this is device-specific or something, though I don't imagine the UI shaders working too well if that were the case):

    Comparison Functions
    • 0 - Always (?)
    • 1 - Never
    • 2 - Less
    • 3 - Equal
    • 4 - LEqual
    • 5 - Greater
    • 6 - NotEqual
    • 7 - GEqual
    • 8 - Always (? This is the default for the UI shaders so I suspect this one is technically the 'correct' Always, but any value beyond it will also count as Always)
    Stencil Operations (these seem to line up with the order they're shown in the docs):
    • 0 - Keep (?)
    • 1 - Zero
    • 2 - Replace
    • 3 - IncrSat
    • 4 - DecrSat
    • 5 - Invert
    • 6 - IncrWrap
    • 7 - DecrWrap
  2. Gambit-MSplitz


    May 16, 2015
    Thank you so much! This should really be somewhere easy to find in the docs... maybe even the shaderlab page.
  3. Alex_May


    Dec 29, 2013
    Good spot - thanks for reporting it and doing the research. I've added it to our list.
  4. Aras


    Graphics Plumber Unity Technologies

    Nov 7, 2005
  5. rainChu


    May 17, 2013
    I'm sorry to bump such an old thread, but I wanted to point out 2 years later that, as of Unity 2018, the documented order of the comparison function enumeration still does not match up with these values in the ShaderLab manual... it gave me a headache for this past half hour. Would you please add it to the documentation to save others the trouble of relying on user support for reference that should be part of the product?