any math v2
Write expressions across ten inputs, get images, masks, or values back
- a
- b
- c
- d
- e
- f
- g
- h
- i
- j
- image1
- mask1
- value1
- image2
- mask2
- value2
- image3
- mask3
- value3
any math v2 is this pack's do-anything calculator node: wire in up to ten arbitrary values as a through j, write up to three math expressions, and get back up to three results - each one automatically routed to an image output, a mask output, or a plain value output depending on what the expression actually produces. It's the most flexible node in this pack's math family, and also the one with the steepest learning curve, because you're writing expressions rather than picking from a dropdown.
The inputs and outputs that matter
Each of expression1, expression2, and expression3 is a free-text field where you write a formula using your wired variables - the default on expression1 is literally a+b, which tells you the basic shape. Leave an expression field blank if you don't need that output slot; the node skips computing it entirely. Masks get treated as 3-channel images for the math, so mixing images and masks in the same expression works without a manual conversion first.
Three toggles change how inputs get prepared before your expression runs. PreprocessingTensor (on by default) unifies batch size, resolution, and channel count across your inputs - the setting to check first if you're mixing shapes and getting an error. RGBA_to_RGB strips the alpha channel down to 3-channel automatically if your input has one. image_clamp clips the result back into the valid 0–1 range - leave it off if you're feeding this node's output into another image math node afterward, since clamping early can throw away information a second pass needed.
The routing logic surprises people: if your expression evaluates to a tensor (an image), it comes out the corresponding image output and the matching mask/value outputs for that slot are empty. If it evaluates to something that isn't a tensor - a number - it comes out value instead, with the image and mask outputs left blank. The node also supports a subset of plain Python methods inside expressions, so watch what type your expression actually returns; it's easy to write something that resolves to a plain number when you expected a tensor, then wonder why your image output is blank.
Installing it
Same pack as everything else here. ComfyUI Manager, search "ComfyUI-WJNodes," or:
cd ComfyUI/custom_nodes
git clone https://github.com/807502278/ComfyUI-WJNodes.git
Restart, find it under WJNode → Math. No models, no extra dependencies for this node specifically.
Where people get burned
Start with PreprocessingTensor - if it's off and you're mixing an image with a mask, or two differently-sized images, that's the first thing to flip on. If an output you expected to be an image comes back empty, check whether your expression is actually returning a tensor rather than a scalar; simplify to something like just a on its own to confirm the variable is wired correctly before layering complexity back in.
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| expression1 | STRING | a+b | — |
| expression2 | STRING | — | |
| expression3 | STRING | — | |
| PreprocessingTensor | BOOLEAN | true | — |
| RGBA_to_RGB | BOOLEAN | true | — |
| image_clamp | BOOLEAN | true | — |
| aopt | * | — | |
| bopt | * | — | |
| copt | * | — | |
| dopt | * | — | |
| eopt | * | — | |
| fopt | * | — | |
| gopt | * | — | |
| hopt | * | — | |
| iopt | * | — | |
| jopt | * | — |
Outputs (9)
| Name | Type | Description |
|---|---|---|
| image1 | IMAGE | — |
| mask1 | MASK | — |
| value1 | * | — |
| image2 | IMAGE | — |
| mask2 | MASK | — |
| value2 | * | — |
| image3 | IMAGE | — |
| mask3 | MASK | — |
| value3 | * | — |