---
title: "vec2"
description: "A 2D vector from two values."
group: "space"
groupTitle: "Shapes, frames & warps"
categoryId: "math"
categorySlug: "math"
categoryTitle: "Math"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/math.ts#L514"
---

# vec2

A 2D vector from two values.

```ts
vec2(x: Val, y: Val): Expr
```

Import `math` from `shaders/std` and use `math.vec2`.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `x` | `Val` |  |
| `y` | `Val` |  |

## Example

```ts
const offset = vec2(params.uniforms.shiftX, params.uniforms.shiftY)
```

## See also

- [`vec3`](/docs/primitives/math/vec3) — A 3D vector from three values, often a color without alpha.
- [`vec4`](/docs/primitives/math/vec4) — A 4D vector, usually the final color with alpha.

## Used by

[ChromaFlow](/docs/components/chromaflow), [Chrome](/docs/components/chrome), [CompressionArtifacts](/docs/components/compressionartifacts), [Crystal](/docs/components/crystal), [FlowingGradient](/docs/components/flowinggradient), [Frost](/docs/components/frost), [Heatmap](/docs/components/heatmap), [Hologram](/docs/components/hologram), [Irradiance](/docs/components/irradiance), [LiquidMetal](/docs/components/liquidmetal), [Marble](/docs/components/marble), [MeshGradient](/docs/components/meshgradient), [Nebula](/docs/components/nebula), [PixelSort](/docs/components/pixelsort), [Plastic](/docs/components/plastic), [ReactionDiffusion](/docs/components/reactiondiffusion), [Satin](/docs/components/satin), [Sparkle](/docs/components/sparkle), [Water](/docs/components/water)