Python node for complex math?

From a performance standpoint, is it better to use multiple math nodes or a single python node when dealing with multiple functions?

I realize it will be easier to simplify using a python node (easier to see redundancy), and probably make better organizational sense to use a single python script rather than a dozen math nodes, but are math nodes more or less efficient?

it is basically the same thing!

unless you want to make a custom nodes in python!

but at least you can do some math using python which is a lot easier I guess

happy cl

So performance-wise Blender sees no difference between the expression (A+B)*C and two math nodes wired such to get the same result?

Good to know.

from math done in python it is probably a little faster
but not from the nodes point of view

mind you still have to write the script to do the math and add the nodes !

and it is not obvious at all

have you already done python nodes in a script ?

happy bl

If you’re using Cycles, then you can’t use Python expressions anyway (though it can be used to generate a group of nodes).

If you’re using BI, I believe it can have python-defined nodes, but it may be a bit slower if the calculations are actually being done in Python and not C.

not certain what you mean by Python expressions?

i’v done cycles nodes scripts it does exist

and you can do math in python and use results to set values for cycles nodes too!

mind you can also do more complicated custom nodes too!

happy cl

I meant the mathematical expression “(A+B)*C” I’ve done a teensy bit of Python in C4D Xpresso to handle rigging math. But not in Blender.

I guess what I am asking is if I have a bunch of math nodes in a cycles material tree would it make sense to compile them all into a single script?

well if nodes are complex and need a lot of parameters
it might be worth but not easy to learn it - I can give you thread for this

can you show some nodes set up for what you mean

if you need a very specific nodes set up
it might be faster to do it in nodes editor

from speed point of view
math done in python would be faster then doing with nodes
for simple reason that you are calling nodes API to do the math which is slower then doing it with python math!

happy cl

I do not have anything in particular. Using strings of math nodes can get kind of cumbersome; a formula node with arbitrary inputs would be nice.

have to remember that nodes do things that you don’t see
and doing it with math may require more work to get equivalent too!

it is possible but not certain how to do it !

would be nice to see some of the math your talking !

happy cl

The Node/Maths Expressons (Lite) addon available at https://github.com/baldingwizard/Blender-Addons/wiki/Dynamic-Maths-Expression (with the full version available on Blender Market) does just that - allows you to enter a textual expression and generates the node group for you. Also allows it to be edited via a custom node within the group, automatically re-building the nodes.

is there a way to perform riemann sums/integrate using python in nodes? preferably as a geometry node, but i’d just like to know if its possible

Not really… at least not without some kind of loop (and plenty of limitations).
Your best option is to do the integration in python, and then use the results as it would fit better (an image, a gridmesh, etc)

i’v seen several python algo to do integral or different ect.
also available in Nump or Scipy

so easier to do i guess in python with exter. lib
doing this with nodes is sort of very sluggish and cumbersome

doing it with nodes means that it calculates all the render pixels
so this takes time !

happy bl