← All ideas
  • Published 6 Nov 2023

Type in equations in nodes

If you want to enter a complex math equation in geometry nodes or shader nodes it can be quite inconvenient. For example, if I want to implement exp(-x^2), I need to create a math node, set it to power, set the exponent to 2, create another math mode, set it to multiply, set the second value to -1, then create another math node and set it to exponential.

It would be much better if I could just type in "exp(-x^2)" directly. I'm envisioning a "math equation" node with inputs x, y, z etc. (ideally you can change their names) and a text box where you can type an equation. Under the hood it would just create a bunch of math nodes, but for some uses this would be much more convenient than creating each node individually, and it would make some complex node graphs a lot easier to read.

To address some of the comments: using Python drivers doesn't help in every situation. It works if there is just one value for x, but it won't work if x is a texture etc., since Python doesn't get access to that kind of data (and can't do, since the node graph needs to be compiled into a shader in order to run). So this would be a separate feature from that.

Also, just in case this is the reason for the downvote, this would obviously be completely optional - if you're not a maths person it wouldn't affect you.

87.5%

Development Status: Open

Upvote 7 Downvote 1
nathaniel
6 Nov 2023

6 Comments

Robin-Zollner

I just posted a comment on another post about exactly this. Right now it takes me something like 5 nodes to just implement a Pythagorean equation to solve for a hypotenuse (used in in an A-frame pitched roof). Currently I am using heavily nested node-groups, but that doesn't help if I for example, solve for a leg instead of a hypotenuse. (I have both functions saved, but it is also starting to clutter up my utilities menu.

Lauloque

Can't you create a driver on a value with a scripted expression?

Edit: you can!

  1. Add two Value nodes, one as the variable you want in your math expression, one on which you will add the driver with the expression
  2. right click the first value > Copy as New Driver
  3. Right Click the second value > Paste Driver
  4. Right click the driven value > Edit Driver
  5. Change it to Scripted Expression
  6. Change the expression to exp(-(default_value)**2)
    ( default_value is the name of the "input variable" created from the first value node. You can change its name in the "input variable" list, but don't forget to do it in the scripted expression too)

demo gif

If you need more variables, you can create more value nodes, right click > copy data path (ctrl shift c) and in the driver editor, add a new single property type variable with nodeTree prop, and paste the path. Give it a name, and use the name as your variable in the expression.

Example:

demo picture

Note that scripted expressions do have some limitations:

nathaniel Author

That's helpful, but I believe it works for global values only. It won't work if x is a texture, for example, or the value of some attribute in geometry nodes.

1
Lauloque

Indeed, I see the issue there.

As a mockup, I guess we could have something similar to the current nodegroups that have a empty grey socket to create new data inputs of varying types, options in the sidebar to control them, ...

mockup

2
modormoder

type in "exp(-x^2)" directly

Just use python to type.

FreeMind

I've made the exact same post a while ago. Can't find it anymore, for some reason. Basically, the math node would have dynamic number of inputs, and each input would be a variable for the equasion (A, B, C, D, E....)