Home

vec4s

vec4s are four-dimensional vectors typically composed of four floating-point components. In shader languages and graphics APIs, a vec4 usually represents x, y, z, and w components. While the term vec4s is plural, it is commonly used to refer to the data type consisting of four floats or to an array of such vectors. Each component is a 32-bit float in most implementations, yielding a 16-byte data structure.

In GLSL, vec4 is a built-in type for a vector of four floats. HLSL uses float4. Mathematically,

Common uses include transforming 3D points by a 4x4 matrix, where a point (x, y, z, 1)

Memory layout is typically tightly packed, and in performance-critical code compilers or engines may align vec4

a
vec4
is
a
column
vector
that
can
be
used
to
represent
positions
in
homogeneous
coordinates,
directions,
colors
with
RGBA
channels,
or
quaternions.
Operations
are
component-wise:
add,
subtract,
multiply
by
a
scalar,
or
by
another
vec4,
etc.
Swizzling
allows
access
to
components
in
different
orders,
such
as
vec4.x,
vec4.yz,
or
vec4.rgb,
depending
on
the
language.
is
multiplied
to
produce
a
new
position
in
clip
space,
and
colors
in
shaders
are
often
handled
as
vec4s
in
RGBA
form.
vec4s
may
also
participate
in
vector
math
like
dot
products,
normalization,
and
linear
interpolation.
data
on
16-byte
boundaries
to
suit
SIMD
units.
In
many
APIs,
vec4s
integrate
with
textures,
vertex
attributes,
and
uniform
blocks.