distance
distance
Calculates the Euclidean distance between two points (in 2D, 3D, or 4D).
Core Advantages
Its core value is semantic clarity and conciseness. `distance(p1, p2)` more intuitively expresses the intent of 'calculating distance' than `length(sub(p2, p1))`, simplifying the node graph and improving readability.
Common Uses
Procedural shape generation (e.g., circular SDFs)
Screen-space vignette effects
Interactive effects (e.g., water ripples, force fields)
3D proximity-based object highlighting
How to adjust
The effect's origin can be moved by changing the position of its two input points (e.g., moving a circle from the screen center to a corner). Tiling and repetition of patterns can be achieved by scaling or modifying the input coordinate space (e.g., `uv().mul(3)`).
Code Examples
1// Calculate the distance from the current pixel to the screen center
2const dist = distance( uv(), vec2( 0.5 ) );