Skip to content

Vector4

public struct Vector4

A vector of four floats, used for a shader vec4 uniform that is not a colour. A colour uniform is read and written as a Color instead.

public Vector4(float x, float y, float z, float w);

Creates a vector from its X, Y, Z and W components.

public float X { get; set; }

The first component, x in a shader vec4.

public float Y { get; set; }

The second component, y in a shader vec4.

public float Z { get; set; }

The third component, z in a shader vec4.

public float W { get; set; }

The fourth component, w in a shader vec4.

static

public static Vector4 Zero { get; }

The vector (0, 0, 0, 0).

static

public static Vector4 One { get; }

The vector (1, 1, 1, 1).

public float Length();

Length (magnitude) of this vector across all four components.

public Vector4 Normalized();

This vector scaled to length 1, keeping its direction. A zero vector returns zero rather than an error.

public float Dot(Vector4 other);

Dot product with other: the sum of the products of matching components.

static

public static Vector4 Lerp(Vector4 from, Vector4 to, float weight);

Linear interpolation from from to to, component by component: a weight of 0 gives from, 1 gives to and 0.5 the midpoint. The weight is not clamped, so values outside 0 to 1 carry on past either end.

override

public override bool Equals(object obj);

True when obj is a Vector4 with exactly equal components.

override

public override int GetHashCode();

A hash of the components, so the vector can key a dictionary or a set.

override

public override string ToString();

The vector as text, for example Vector4(1, 0, 0, 1).

static

public static Vector4 operator +(Vector4 a, Vector4 b);

Adds two vectors component by component.

static

public static Vector4 operator -(Vector4 a, Vector4 b);

Subtracts b from a component by component.

static

public static Vector4 operator -(Vector4 a);

Negates every component.

static

public static Vector4 operator *(Vector4 a, float s);

Multiplies every component of a by s.

static

public static Vector4 operator *(float s, Vector4 a);

Multiplies every component of a by s.

static

public static Vector4 operator /(Vector4 a, float s);

Divides every component of a by s. Dividing by zero gives infinite or NaN components, not an error.

static

public static bool operator ==(Vector4 a, Vector4 b);

True when all four components are exactly equal.

static

public static bool operator !=(Vector4 a, Vector4 b);

True when any component differs, compared exactly.

Generated from the CRUMB source, commit fcec660d, 2026-10-29.