- Home /
"Stencil Operation" property setup?
I know when declaring the properties for a shader there are some types of "input": float, range, color, 2D.
but when I try to set up a Stencil Operation as a property. how to do this? I mean what I know that Stencil Operation is one of this list (Greater, GEqual, Less, LEqual, Equal, NotEqual, Always, Never) so then how to indicate which op from the editor.
I saw a line like this:
_StencilOp ("Stencil Operation", Float) = 0
so what "0" stands for?
Answer by Bunny83 · Apr 05, 2021 at 10:51 AM
Well, Unity has the enums Rendering.StencilOp and Rendering.CompareFunction which do reflect those int values. Unfortunately the documentation does not mention the actual index values. However since you can and should use the enum anyways this shouldn't really matter ^^. Though if you do want / need to know those values, someone posted them over here, though this list may not be up to date. The best source would be looking up the declaration of the enums in the source: CompareFunction and StencilOp. I'm sure there aren't much changes happening in those enums over time, but if you really want to be sure you can use ILSpy or any other reflector and look up the enum in your current Unity version.
Though as I said you usually want to use the enums directly. You may need to cast them to int in order to use them.
Good. but what about the "color mask" property? do you have an idea? like this line: _ColorMask ("Color Mask", Float) = 15
The color mask is as the name suggests a bit mask. The enum for it is right between the two enums I just linked ^^. The enum is called ColorWriteMask. The bits are ordered from leaset significant to most significant in the order A (1), B (2), G (4), R(8). So a value of 0x0F (or "15" or "00001111b") is just all 4 channels while a value of 14 (0x0E or "00001110b") would only write the 3 color channels but not the alpha channel. Since it's a bitmask you would combine the different bits using the bitwise or operator |
.
ColorWriteMask mask = ColorWriteMask.Red | ColorWriteMask.Blue;
This mask would only write the red and blue channel and would represent a value of "10" (0x0A or "00001010b")