Added Equals To mode to all nodes. Used https://developer.blender.org/D507 as a template.
Diff Detail
Event Timeline
The paths are wrong here? e.g. source/blender/c, please re-submit a proper git patch. Or just link the raw one.
| source/blender/makesdna/ | ||
|---|---|---|
| 1016 | You must add the new mode after the current ones. Keeping the enum order is important for file compatibility. | |
I would suggest using the ternary operator wherever applicable.
| source/blender/compositor/operations/COM_MathBaseOperation.cpp | ||
|---|---|---|
| 328 ↗ | (On Diff #3802) | Style: output[0] = (inputValue1[0] == inputValue2[0]) ? 1.0f : 0.0f; |
| source/blender/gpu/shaders/gpu_shader_material.glsl | ||
| 296–299 ↗ | (On Diff #3802) | outval = (val1 == val2) ? 1.0 : 0.0; |
| source/blender/nodes/shader/nodes/node_shader_math.c | ||
| 213–216 ↗ | (On Diff #3802) | r = (a == b) ? 1.0f : 0.0f; |
| source/blender/nodes/texture/nodes/node_texture_math.c | ||
| 179–182 ↗ | (On Diff #3802) | *out = (in0 == in1) ? 1.0f : 0.0f; |
Looks fine/straightforward, though would be good to note some use case.
float equality prone to failing with minor precision issues, wouldn't it be better to have a threshold (epsilon?) - it can be set to 0.0 if you really want this behavior.
Comparing floats should use epsilon, otherwise you can have all sort of weird and wonderful artifacts. And at the same time I actually think it's time to add a node group presets where you can have a node group which consists of min/max nodes and exposes epsilon to the interface.
That way we can stop expanding base set of nodes and still keep artists happy with much easier ways to construct their node trees.
EDIT: I'm not really fan of adding epsilon to the math node, it'll be only used by a single operation in there.
@Campbell Barton (campbellbarton), @Sergey Sharybin (sergey) How should this be done, then? I don't think adding another field, which only applies to _one_ specific mode is a good idea.
very useful operation but it doesn't work with cycles shaders (always spits out the first input)
testfile
i use equals quite often so i've built my own node
but with this function built in i could reduce the amount of math nodes from 14 to 4 for my instance node ( -4 math nodes for the if == node)
in my shader i use 10 instance nodes so in total 100! math nodes less - should give a tiny speedup :)
I think we concluded (after a chat with @Sergey Sharybin (sergey), in IRC) that this is not gonna get accepted as it is, because it should allow the use of a threshold; however, adding another field that would only be used for one mode is also not desirable. So, what about adding this field, but only displaying it when appropriate? And the rest of the time, have in collapsed, or something.
I would fully support the idea of dynamically creating/destroying outputs in certain node types depending on what you do. This would also mean that the second output would disappear if you use operations like sin and cos and would pave the way for a versatile 'equation' node type (or mode) where if you typed in a*(b-c), you would have three outputs labeled a, b, and c.
The current methodology where the number of inputs is fixed adds a certain degree of rigidity to a system that should be as flexible as possible, this would create a number of new possibilities.
