Math Distance*

Preview
Performance Cost 🟢 Low
Signal Type Vector → Float
Implementation Native Compiled C++
Devices (Cycles) CPU / GPU (1:1)

Math Distance calculates the spatial separation or relationship between two vectors. While the standard "Distance" node only offers Euclidean length, this utility provides a comprehensive set of 5 distinct metrics: Euclidean, Manhattan, Chebyshev, Minkowski, and Cosine. These different modes allow you to shape distance fields into spheres, diamonds, cubes, or angular gradients, making it a fundamental building block for procedural shaping, proximity effects, and pattern generation.

Usage & Behavior

Vector Logic: Practical Applications

The power of this node comes from what vectors you compare. Here are three standard workflows:

1. The Snow Mask (Direction)
Mode: COSINE
Input 1: Surface Normal (N)
Input 2: Vector (0, 0, 1) [Up]

By calculating the Cosine Distance between the surface Normal and the "Up" vector, you isolate surfaces facing the sky. Use this to mask snow, dust, or rain wetness on top of objects.

2. The Proximity Field (Position)
Mode: EUCLIDEAN
Input 1: Shading Point (P)
Input 2: Object Location

Calculates the physical distance from the shading point to a specific object (like an Empty). Use the result to drive a glow that gets brighter as an object gets closer, or to create a spherical mask in 3D space.

3. The Shape Generator (UV)
Mode: CHEBYSHEV / MANHATTAN
Input 1: UV Coordinate
Input 2: Center (0.5, 0.5, 0)

By measuring the distance from the center of a UV tile, you create geometric gradients. Chebyshev creates a square box gradient (perfect for paneling), while Manhattan creates a diamond gradient (sci-fi shields).

Euclidean
Manhattan
Chebyshev
Cosine (Normal and Up Vector)

The visual output of this node changes drastically depending on the Mode. If you calculate the distance from the center (0,0,0) to the current shading point (P), Euclidean creates a smooth radial gradient (like a ball), while Manhattan creates a pyramid/diamond shape, and Chebyshev creates a box. Cosine is unique—it doesn't measure length, but direction.

Best Used For: Custom falloff shapes (Box/Diamond/Sphere), Voronoi-style cell generation, comparing similarity between colors, and checking if two objects are facing the same direction.

Key Features

  • 5 Geometric Norms: Covers L1, L2, L-Infinity, and Angular metrics.
  • Optimized Math: Calculates complex relationships in a single atomic operation.
  • Shape Control: Turns simple distance gradients into geometric primitives.

Deep Dive: Metric Geometry

How you measure "distance" defines the shape of the world.

Euclidean ($L^2$)

The ruler distance. "As the crow flies."
Shape: Sphere / Circle.

Manhattan ($L^1$)

Taxicab geometry. $|x| + |y| + |z|$.
Shape: Diamond / Octahedron.

Chebyshev ($L^\infty$)

Chessboard distance. $max(|x|, |y|, |z|)$.
Shape: Cube / Square.

Cosine Similarity

Angular difference. Ignored length.
Shape: Conical Gradient.

Parameters

Mode Enum
Selects the distance metric to use:
  • EUCLIDEAN: Standard physical distance. $ \sqrt{x^2 + y^2 + z^2} $.
  • MANHATTAN: Sum of absolute differences. Useful for "tech" patterns or circuit logic.
  • CHEBYSHEV: Maximum axis difference. Creates square/box falloffs.
  • MINKOWSKI: Generalized $L^p$ distance.
  • COSINE: Returns the cosine of the angle between the two vectors (1.0 = Same direction, 0.0 = 90 deg, -1.0 = Opposite).
Input 1 Vector
The starting point/vector.
Input 2 Vector
The target point/vector.

Quick Recipes

Practical uses for different metrics.

Box Mask

  • Mode CHEBYSHEV
  • Input 1 Object Coords
  • Input 2 (0,0,0)
Creates a square/cube gradient radiating from the center. Useful for masking boxy objects.

Facing Ratio

  • Mode COSINE
  • Input 1 Normal (N)
  • Input 2 (0,0,1) [Up]
Checks how much the surface is facing "Up". Returns 1.0 for flat tops, 0.0 for vertical walls.

Tech Forcefield

  • Mode MANHATTAN
  • Input 1 Object Coords
  • Math Fraction
Applying a modulo/fraction to Manhattan distance creates repeating diamond-shaped pulses.
↑ Back to Top

Leave a Reply