Is XOR possible in compositing

I have a scene with three suns, each in its own lightgroup. In compositing, I set up the nodes to use the sun that I want, and to adjust it’s colour, brightness etc.

Is it possible to set up the nodes in such a way that, if the brightness of any of them is set to a non-zero value, the other two must be zero, or even a way to have a check box to select which to use in compositing (this must be a compositing setup, so that I only render once).

I’m guessing not without resorting to python, but if anyone can prove me wrong I’d be grateful.

You can make any logical gate in Blender very easily with the Math node- some combination of Greater Than, Less Than, Maximum, and Minimum will do it. For example, for an And gate, you plug a Greater Than and a Lesser Than node into a Minimum node. For Or, you change the Minimum to a Maximum. Use that output of that into a Mix node, in your case, or actually you’ll need two Mix nodes- plug suns 1 and 2 into the first one, plug the output of that into the second one, with sun 3 as the second input, and another logical Math combination as the factor

But surely the nodes are evaluated in a linear manner, and so any solution such as that will always favour the first sun, and then the second. If I change sun 2, and either sun 1 or sun 3 was previously selected, it won’t automatically disable the previous selected sun? In fact, it could end up in a weird loop where the newly selected sun is immediately de-selected again in favour of the one that has priority in the evaluation order.

I’m not sure, you should try it. There’s definitely a fairly simple combination of Math nodes and Mix nodes that will get close, at least, but I’m not sure if it’ll actually work

Isn’t quite well explained the exact effect that you’re looking for, but XOR equation in Nuke is A(1-b) + B(1-a), A and B are RGB inputs, a and b alphas.

1 Like

You might want to mix the background with this somehow… value 0, 0.5 and 1 chooses Light1, Light2 or Light3…

XOR math is:

``````IF (x == y)
return 0
ELSE
return 1
``````

You can do this with COMPARE Math Node and MIX node easily.

Thank you, all. I was that focused on an XOR that I missed the blindingly obvious (that you have now given me). A single value input connected to three compare nodes (comparing 1,2 and 3) connected to a multiply node connected to the brightness.

Now I just feed the relevant value, and that’s the only sun used, exactly what I wanted.

Thanks again. This node setup just keeps getting more complicated, with layer upon layer of nested groups. But it gets me this.

1 Like