sub
Performs fundamental mathematical subtraction (`a - b`). It's a core building block for calculating differences between vectors, colors, or coordinates in a shader graph.
Core Advantages
Offers an intuitive, chainable syntax (`a.sub(b)`) that improves readability, while flexibly handling multiple inputs and providing type-safe automatic conversions (e.g., vec3 - float).
Common Uses
Calculating directional vectors, such as the direction from a surface point to a light source
Implementing color blending effects like the 'Difference' mode or simple inversion filters
Driving geometric displacement or procedural modeling by calculating a vector from a center point
How to adjust
Since it's basic subtraction, changing its inputs directly and linearly affects the output. Visually, this translates to shifting or offsetting values. For example, subtracting a `vec2` from `uv()` coordinates effectively moves the origin of the UV space.
Code Examples
1
2// Get a vector pointing from the center (0.5, 0.5) to the current UV coordinate
3const directionVector = uv.sub(vec2(0.5, 0.5));
4
5// Use its length to create a radial gradient
6const gradient = directionVector.length();
7