# XOR node for edge matte

Is there an XOR node to XOR a dilated-out matte with a dilated-in matte, so that you just have the edge of the object masked; to do things like edge blur; or color correcting... Like brightness etc. ?

There is not an exclusive-or (Xor) function in shader nodes; but you can synthesize an Xor using two nodes. Here is a very contrived example of this:

and here is a plane that demonstrates the result:

Here I have coded, roughly, "the region of the UV map where $$X \lt .8$$ or $$X \gt .9$$"

Note that I'm actually computing the negative of the XOR. The white region represents the truth value of the XOR but is output on the 0 value of the compare node. To make a true XOR, add a math node after the compare and set it to subtract the compare output from 1.

Basically this works as follows: The Greater Than and Less Then nodes produce Boolean values, 0 for False, and 1 for True. The required input to the XOR must have this property. XOR should produce a 1 if either value is True but not both. If you look at this as an arithmetic problem, you can add the two Boolean input values. This will produce 0 or 2 if the XOR is not satisfied, or 1 if it is.

So the XOR comes down to adding two integers and comparing the result to 1.

The mix node is just for visualization. If Fac is 0, it will produce black, otherwise white.

It's a bit fragile and my own implementation has some extra logic to convert the inputs to Booleans using C logic: Anything not equal to 0 is True.

Using XORs on both the X and Y UV values you can produce the mask you're looking for.

Mix RGB node in Difference mode can work as XOR: