Using CustomDepth Stencil and Bitmask to toggle additional effects?

I have 2 post-process materials in which I’d like to use the CustomDepth Stencil values to toggle a secondary effect in the materials.

In the first one:

  • 1st bit: Do nothing if 0, have a purple outline if set to 1.
  • 2nd bit: If set to 1, ignore the 1st bit and have a red outline.
  • 3rd bit: If set to 1, ignore the 1st and 2nd bits and have a green outline.

In the second one:

  • 4th bit: Multiply with purple if set to 0, add an orange color if set to 1.

In both of them:

  • 8th bit: Ignore the post process material (simply have PostProcessInput0 as emissive color)

My intention is to have, say, a StaticMesh with a Stencil value of 5 (0101) that when switching between post process materials, it is shown to have a purple outline in one and have an orange-ish color in the other.
I tried using a bitmask for this, but it only renders the effect if it only has its corresponding bit set to 1, which is not what I’d like to have.

Show how the stencil buffer looks.

It looks like this:

I’m also showing how I used the bitmask node in the PP material:

I see now. You want it to work as binary AND?
Unfortunately, BitMask is float function, it only could match the value of the bit.
Bitwise operators are available for SM4, but you have to write them yourself via Custom Node.
The other way probably will be dividing the value 8 (or 7?) times by 2 and masking it each time.