Page MenuHome

Logical operations (AND, XOR, OR, NOT, ==) in maths nodes
Closed, ArchivedPublicPATCH

Description

I have added the operations for bitwise (XOR, OR, AND) operations in the maths node. These convert the floating variable into integers before appying. I have also included a NOT operation, which acts by simply taking the float value from 1, and a equals(==) test. These operations are available in all the math nodes (cycles, compositing and textures). All of these operations can already be performed by combining other basic maths operations but I found that for certain advanced cycles materials this added unnecessary complexity.

This is actually my first patch, so if there's any mistake or advice then please let me know.

Stuart

Event Timeline

I think this patch would be more useful if it supports real value from 0 to 1.
For example, following equations can be derived if we interpret input/output values as probabilities.

AND: result = x * y
NOT: result = 1 - x
OR: result = 1 - (1 - x) * (1 - y) = x + y - xy
XOR: result = (x + y - xy) * (1 - x * y)

Here, x, y are input values and should be clipped from 0 to 1.

Sorry. XOR equation was wrong.

XOR extension for real values has some choices, I recommended
x + y - 2xy
for better symmetries.

I agree and have made an updated patch exactly as you describe. Thanks!

Sergey Sharybin (sergey) changed the task status from Unknown Status to Unknown Status.Apr 16 2015, 1:41 PM
Sergey Sharybin (sergey) claimed this task.

The issue with this patch is that it adds quite reasonable amount of complexity to SVM node, which does not have chance to be optimized out (as it's possible with OSL nodes). This means regular kernel might become slower just because some really specific operations.

I'd prefer to keep nodes a small basis which then can be used to construct expressions. The thing which would help with this is having some node group templates, which is actually in the list to be done anyway.

So thanks for the patch, but we can't apply it.