Vec4BinaryOperation
Add, subtract, or cross two 4D vectors
- a
- b
- VEC4
Whenever a graph is carrying an RGBA color, a quaternion, or a homogeneous coordinate as one VEC4 instead of four loose floats, this is the node that combines two of them. Vec4BinaryOperation takes two four-component vectors and returns a third.
It's part of ComfyMath, evanspearman's math/logic pack, and it's the 4D sibling of CM_Vec3BinaryOperation - same three-way op choice, one more component.
How it works
Feed it a and b, both VEC4 (default [0, 0, 0, 0]), and pick an op: Add, Sub, or Cross. Add and Sub are straightforward - component-wise addition or subtraction, useful for blending two RGBA colors or combining offsets that happen to be carried as VEC4.
Cross needs a flag, and a bigger one than the Vec3 version of this node: cross product is a 3D-specific operation (it's also defined, more obscurely, in 7D) - there is no standard cross product for general 4-component vectors the way there is for VEC3. So what this node actually computes when you pick Cross on two VEC4 inputs isn't something to assume from the name alone. If you need it, feed it a known test case first (two vectors where you can predict the "correct" perpendicular-style result by hand) and check the output matches what you expect before building anything downstream on top of it.
Inputs and outputs
op- Add, Sub, or Cross.a(VEC4, default[0, 0, 0, 0]) andb(VEC4, default[0, 0, 0, 0]) - the two vectors being combined.- Output:
VEC4- the result, ready to feed into another ComfyMath vector node.
How to install it
Through ComfyUI Manager: search ComfyMath, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/evanspearman/ComfyMath.git
then restart ComfyUI. No dependencies, no models - plain Python arithmetic.
Common issues & troubleshooting
Cross on VEC4 doesn't behave like the textbook 3D cross product. As above - there's no standard 4D cross product, so don't assume this generalizes the same way the VEC3 version does. If what you actually need is a real, unambiguous cross product, do it on VEC3 values with CM_Vec3BinaryOperation instead, and only bring the result into VEC4 territory (adding a fourth component) afterward if you need one.
You wanted a single number (alignment or distance), not another vector. That's CM_Vec4ToScalarBinaryOperation with Dot or Distance - this node always returns a VEC4.
A VEC4 output won't wire where you expect. VEC4 is a ComfyMath-specific type, distinct from four separate FLOAT sockets. If a downstream node wants individual components, split the vector first rather than wiring VEC4 straight into a FLOAT input.
Missing node error on a shared workflow. Install ComfyMath via Manager as above, then reload.
Not sure you need Vec4 nodes. Most generation workflows never touch them - they show up when you're doing your own color, quaternion, or homogeneous-coordinate math rather than a standard checkpoint-to-image pipeline.
The pack looks unmaintained. A 2024 community thread noted the author had stepped back from active development. The Vec3/Vec4 side of ComfyMath is its quietest corner, so treat it as small and stable rather than actively developed.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| op | COMBO | 3 options: Add, Sub, Cross | |
| a | VEC4 | 0,0,0,0 | — |
| b | VEC4 | 0,0,0,0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| VEC4 | VEC4 | — |