Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Stencil Op/Comparison Values

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

  1. Giometric

    Giometric

    Joined:
    Dec 20, 2011
    Posts:
    170
    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. MSplitz-PsychoK

    MSplitz-PsychoK

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

    Alex_May

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

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,612
    PuzzledBoy likes this.
  5. rainChu

    rainChu

    Joined:
    May 17, 2013
    Posts:
    1
    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?
     
  6. PuzzledBoy

    PuzzledBoy

    Joined:
    Sep 9, 2014
    Posts:
    23
  7. caochao88_unity

    caochao88_unity

    Joined:
    May 16, 2019
    Posts:
    26
    still not updated
     
    marie-hmm and StijnPaladin like this.
  8. bdavis1000

    bdavis1000

    Joined:
    Oct 4, 2013
    Posts:
    14
    On Switch and possibly other platforms, a comparison function value of 0 appears to stop the material from rendering, while 8 functions as expected. This stumped me for a while. These values should really be in the docs, along with an explanation on what the difference between 8 and 0 is. Additionally it would be nice for them to just be a dropdown in editor instead of an int
     
    zchajax_sc likes this.
  9. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    200
    somewhat related, the Enums do not function as labeled & can be reproduced using URP in 2019.3.3f1 & validating the depth stencil state with RenderDoc (though it is not a URP issue)

    In URP RenderObjects.cs line 28, the depthCompareFunction is defined as CompareFunction.LessEqual

    When taking a RenderDoc capture, checking in the API Inspector it can be seen that ID3D11DeviceContext::OMSetDepthStencilState event has the depth state being set as GreaterEqual

    Other elements in the Enum have similar unexpected behavior, I logged a bug on it recently & hopefully it will be fixed.
     
    dev_starberry likes this.
  10. test437290802

    test437290802

    Joined:
    Jun 4, 2020
    Posts:
    2
    Comparison Functions
    • 0 - Disabled
    • 1 - Never
    • 2 - Less
    • 3 - Equal
    • 4 - LEqual
    • 5 - Greater
    • 6 - NotEqual
    • 7 - GEqual
    • 8 - Always
     
  11. test437290802

    test437290802

    Joined:
    Jun 4, 2020
    Posts:
    2
unityunity