Vector Math
Performs one of 17 vec2 math operations. Outputs a vec2 result and a scalar for length/distance/dot operations.
Category: Math Menu path: Math > Vector Math
Ports
| Port | Type | Direction | Description |
|---|---|---|---|
a | vec2 | input | First vector operand |
b | vec2 | input | Second vector operand (not used by unary operations) |
out | vec2 | output | Vector result |
scalar | scalar | output | Scalar result (populated by Length, Distance, and Dot operations) |
Parameters
| Param | Type | Default | Description |
|---|---|---|---|
operation | enum | Add | The vector operation to perform (see table below) |
a | vec2 | (0, 0) | Fallback value for input A when not connected |
b | vec2 | (0, 0) | Fallback value for input B when not connected |
t | scalar | 0.5 | Interpolation factor (Lerp only) |
The Properties panel automatically shows only the params relevant to the selected operation.
Operations
Binary (A, B)
| Operation | Result (vec2) | Scalar output |
|---|---|---|
| Add | A + B | -- |
| Subtract | A - B | -- |
| Multiply | A * B (component-wise) | -- |
| Divide | A / B (component-wise) | -- |
| Scale | A * B.x (uniform scale by B's x component) | -- |
| Min | (min(Ax, Bx), min(Ay, By)) | -- |
| Max | (max(Ax, Bx), max(Ay, By)) | -- |
Unary (A only)
| Operation | Result (vec2) | Scalar output |
|---|---|---|
| Length | A (unchanged) | length(A) |
| Normalize | A / length(A) | -- |
| Negate | -A | -- |
| Abs | `( | Ax |
| Floor | (floor(Ax), floor(Ay)) | -- |
| Ceil | (ceil(Ax), ceil(Ay)) | -- |
Two-operand with scalar output
| Operation | Result (vec2) | Scalar output |
|---|---|---|
| Distance | A (unchanged) | distance(A, B) |
| Dot | A (unchanged) | dot(A, B) |
| Rotate | rotate(A, B.x radians) | -- |
Interpolation
| Operation | Result (vec2) | Scalar output |
|---|---|---|
| Lerp | A + (B - A) * t | -- |
How It Works
VectorMath is a lightweight CPU-only node that operates on vec2 values. No GPU textures are allocated. Operations that produce both a vector and scalar result (Length, Distance, Dot) populate both output ports simultaneously.
When an input port is not connected, the corresponding param value is used. When connected, the incoming value overrides the param.
Usage Examples
Basic: Offset position
Time.seconds -> Math (Sin) -> MakeVector (x driven, y: 0) -> VectorMath (Add, b from Constant vec2). Creates a sinusoidal horizontal oscillation added to a base position.
Distance-based effect
VectorMath (Distance, a: point position, b: center) -> Math (Remap) -> drives another param. Creates a radial falloff from a center point.
Normalized direction
VectorMath (Subtract, a: target, b: source) -> VectorMath (Normalize). Gets the unit direction vector between two points.
Tips
- The
scalaroutput port is only meaningful for Length, Distance, and Dot -- for other operations it may not carry useful data - Unary operations ignore input B and hide the
bparam in Properties - Lerp shows the
tparam; all other operations hide it - Use BreakVector to extract individual components from the vec2 result
Related Nodes
- Math -- scalar math operations
- MakeVector -- combine scalars into vec2/vec3
- BreakVector -- split vec2/vec3 into scalar components
- Constant -- fixed vec2 value source