Input Adaptive Math Node
Problem
When working with Shaders, we often have to perform math operations on vectors . The current nodal interface in blender deals nicely with operations on values, however operations on vectors are very inconvenient. As you know, when you connect a vector or color to Math Node , it will be automatically converted to a value and the operation will be performed on this value. We do not have a dedicated node that allows us to perform any mathematical operations on vectors and colors (MixRGB only support few of them). Currently, the only method to do it in Blender is to separate vector into 3 values, perform math operations on them in parallel and then combine them into a new vector. Technical artists who work with other nodal systems certainly know that the blender solution is cumbersome and slow. In addition, networks created in this way are more difficult to compile and have lower performance!
Solution
Most programs that use nodal systems have a much better solution. Input Adaptive Nodes . Principle is simple, if you connect values to the node, it performs the operations on values and output is a value. If you connect vectors, node performs component wise operations on vectors and output is a vector. Many systems allow you to use a vector in combination with a value. This allows uniform scaling using multiplication, division of space into equal cubic cells by means of the Round operation, etc.
I propose to implement Input Adaptive Math Node in Blender. This solution will greatly improve work with shaders. I think we need that for Nodify Everything project in order to work efficiently with vectors.
You're probably wondering about backwards compatibility or what if you WANT to turn vector into value. Let's start from scratch.
- Input sockets in Math Node should be colored white . This will suggest a new type of input socket - the Adaptive one, when input slots are empty, it works like current Math node. User can specify values in input fields and node perform operation on values.
- When a Value is connected socket changes color to gray. The rest works above.
- When a Vector / Color is connected. Node performs component wise operations on vector / color and output is a vector / color. Sockets changes color to purple or yellow accordingly.
- If you want to convert Vector / Color into Values (like it works now automatically) you can enable new "Convert Inputs" option. This will be needed to preserve backward compatibility with existing shaders. When loading old scenes, the option should be turned on automatically in all math node instances. On new scenes I propose to turn off by default.
- When Vector and Color are connected to node output type is same as first input type.
See the table of possible input combinations and gif with examples below.
"Why not just Vector Math Node?"
We could add missing math operations to Vector Math Node and call it a day. In other nodal systems each math operation is a different type of node. The strength of Blender's Math Node is the ability to perform various types of operations with only one node. To add next operation, you simply copy the node, link it and change the type of operation. It's much faster than searching for specific node in the menus or typing in search field. What's more, if you want to completely change the sequence of operations, you don't need to reorganize the entire node tree. Just change the types of operations (even faster using CTRL+Scroll), adjust your values, done! It encourages us to experiment. This method of interaction and the fact that nodes display the values makes workflow much faster than in other systems. However, as I mentioned, this applies only to operations on values. Here is the issue with Vector Math Node. If we simply add the missing mathematical functions to it, we will need to use 2 types of nodes at the same time, like in other systems. This will result in much slower workflow. Two steps forward, one step back. I believe that with the correct implementation of Input Adaptive Math Node we will get the best possible nodal interface!
9 Comments
I love your suggestion for Input Adaptive Math Node. I tried to look you up on Facebook, but I didn't know which namesake was yours.
I hope I can interest you to join Blender Maths, a new group in Facebook. You'll love meeting black-belt mathematicans there. Feel free to join. If you refuse, no worries. 🙂
facebook.com/groups/570271320154049/
Thanks! I joined. :)
Great idea !! :)
Not to mention that vector multiplication can mean something entirely different than component-wise multiplication. That could be a huge difficulty if we just add to the Vector Math node, rather than explicitly say that the generalized 'Math' node performs component-wise operations while operations specific to, say, Vectors are in their own separate node.
Really good idea!
This is a great idea! I quickly checked the different maths operations and they all make sense in a Vector and Color context.
How would you feel about having separate Vector, Value and Color outs for the sake of visual clarity? Changing the output type violates the principle of least surprise a bit. For multi-valued output, Value could output the first member of the vector/colour (like usual); for Value output, the Vector/Colour could contain the output Value three times.
Or in the case of two-vector input for "Multiply", you get the Cross Product from the Vector out and the Dot Product from the Value out...
Do you think it is feasible to roll all the Vector Math functions into the Math node?
An update on this, since the last summer of code project there has been a vector maths node with lots of functions. The math node has also been updated with some functions which makes it quite crowded.
Personally i think the way it's being done is indeed slower but more intuitive, which is important considering how tough vector maths can be if one's not familiar (ie. the user will have to guess they have to add two vectors to a multiply function to get a cross product)
I think that this suggestion should be expanded to more nodes than just the math node. As an example it could be useful to be able to create node groups that are input adaptive. That would however require that we had logic, control flow nodes and some concepts of type recognition.
Sure! Many nodes could use same logic for handling different inputs. Control flow nodes are also something we should add someday but I wanted to focus this proposal on one thing.