---
title: "vec3: shader function examples, uses and input limits"
description: "vec3 groups 3 components into a vector. A single scalar broadcasts to every component."
url: https://typeshade.dev/reference/functions/vec3/
language: en
---

# `vec3`

Function

`vec3` groups 3 components into a vector. A single scalar broadcasts to every component.

## Compare examples

Compare a broadcast with distinct components and a zero value. Each component retains its position.

**Example 1`vec3(1.)`**

`1` `1` `1`

Components in this example

**Result**

`[1,1,1]`

**Example 2`vec3(1., 2., 3.)`**

`1` `2` `3`

Components in this example

**Result**

`[1,2,3]`

**Example 3`vec3(0.)`**

`0` `0` `0`

Components in this example

**Result**

`[0,0,0]`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use vectors to represent coordinates, directions, colours, or several independent values of the same type.

## Inputs and limits

A constructor does not normalize a direction. Integer, boolean, and floating-point vectors have different component types; this compiler emulates `f64` vectors in software.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`length`](https://typeshade.dev/reference/functions/length/)
- [`normalize`](https://typeshade.dev/reference/functions/normalize/)
- [`dot`](https://typeshade.dev/reference/functions/dot/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Builds a `vec3` from three scalars, a `vec2` and a scalar, or broadcasts a single scalar to all three components.

## Syntax

```ts
declare function vec3<T = f32>(): VecFor3<T>
declare function vec3<T = f32>(x: number, y: number, z: number): VecFor3<T>
declare function vec3<T = f32>(v: vec2, z: number): VecFor3<T>
declare function vec3<T = f32>(x: number, v: vec2): VecFor3<T>
declare function vec3<T = f32>(scalar: number): VecFor3<T>
declare function vec3<T = f32>(v: vec3): VecFor3<T>
declare function vec3<T>(x: bool, y: bool, z: bool): VecFor3<T>
declare function vec3<T>(scalar: bool): VecFor3<T>
declare function vec3<T = f32>(v: vec3i): VecFor3<T>
declare function vec3<T = f32>(v: vec3u): VecFor3<T>
declare function vec3<T = f32>(v: vec3b): VecFor3<T>
declare function vec3(v: vec3f64): vec3
```

A `number` in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

`type f32 = number & { readonly [f32Tag]?: true }`

A `number` you write as a type is inferred from its uses, and `f32`, `i32` and `u32` fix a width; [the TypeScript constructs page](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

A signature may name a type the ambient file declares for its own use. These are those declarations.

**`VecFor3`**

`type VecFor3<T> = VecElemOf<T, vec3u, vec3i, vec3f64, vec3b, vec3>`

## Parameters

- `x` optional `number``bool`
- `v` optional `vec2``vec3``vec3i``vec3u``vec3b``vec3f64`
- `scalar` optional `number``bool`
- `y` optional `number``bool`
- `z` optional `number``bool`

## Return value

`VecFor3<T>``vec3`

## Examples

- [`path/palette/palette.shade.ts`](https://typeshade.dev/guide/examples/palette/)
- [`path/ray-tracer/ray-tracer.shade.ts`](https://typeshade.dev/guide/examples/ray-tracer/)
- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/guide/examples/capsule-corp-namek-class/)
- [`gallery/domain-warp-twin/domain-warp-twin.shade.ts`](https://typeshade.dev/guide/examples/domain-warp-twin/)
- [`gallery/hillshade-twin/hillshade-twin.shade.ts`](https://typeshade.dev/guide/examples/hillshade-twin/)
- [`gallery/julia-twin/julia-twin.shade.ts`](https://typeshade.dev/guide/examples/julia-twin/)
- [`gallery/kaleidoscope-twin/kaleidoscope-twin.shade.ts`](https://typeshade.dev/guide/examples/kaleidoscope-twin/)
- [`gallery/mandelbrot-twin/mandelbrot-twin.shade.ts`](https://typeshade.dev/guide/examples/mandelbrot-twin/)
- [`gallery/ocean-twin/ocean-twin.shade.ts`](https://typeshade.dev/guide/examples/ocean-twin/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/guide/examples/path-tracer/)
- [`gallery/plasma-twin/plasma-twin.shade.ts`](https://typeshade.dev/guide/examples/plasma-twin/)
- [`gallery/rt-renderer-class/rt-renderer-class.shade.ts`](https://typeshade.dev/guide/examples/rt-renderer-class/)
- [`gallery/starfield-twin/starfield-twin.shade.ts`](https://typeshade.dev/guide/examples/starfield-twin/)
- [`gallery/tunnel-twin/tunnel-twin.shade.ts`](https://typeshade.dev/guide/examples/tunnel-twin/)
- [`gallery/voronoi-twin/voronoi-twin.shade.ts`](https://typeshade.dev/guide/examples/voronoi-twin/)
- [`gallery/fp64-burning-ship-twin/fp64-burning-ship-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-burning-ship-twin/)
- [`gallery/fp64-cancellation-twin/fp64-cancellation-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-cancellation-twin/)
- [`gallery/fp64-checker-plane-twin/fp64-checker-plane-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-checker-plane-twin/)
- [`gallery/fp64-clock-twin/fp64-clock-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-clock-twin/)
- [`gallery/fp64-julia-twin/fp64-julia-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-julia-twin/)
- [`gallery/fp64-lane-stripes/fp64-lane-stripes.shade.ts`](https://typeshade.dev/guide/examples/fp64-lane-stripes/)
- [`gallery/fp64-loran-twin/fp64-loran-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-loran-twin/)
- [`gallery/fp64-mandelbrot-de-twin/fp64-mandelbrot-de-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-mandelbrot-de-twin/)
- [`gallery/fp64-newton-twin/fp64-newton-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-newton-twin/)
- [`gallery/fp64-rtc-twin/fp64-rtc-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-rtc-twin/)
- [`gallery/fp64-sine-sweep-twin/fp64-sine-sweep-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-sine-sweep-twin/)
- [`gallery/array-literal-ramp/array-literal-ramp.shade.ts`](https://typeshade.dev/guide/examples/array-literal-ramp/)
- [`gallery/array-methods/array-methods.shade.ts`](https://typeshade.dev/guide/examples/array-methods/)
- [`gallery/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/guide/examples/bit-bump/)
- [`gallery/bitfield-bands/bitfield-bands.shade.ts`](https://typeshade.dev/guide/examples/bitfield-bands/)
- [`gallery/block-scope/block-scope.shade.ts`](https://typeshade.dev/guide/examples/block-scope/)
- [`gallery/bool-select/bool-select.shade.ts`](https://typeshade.dev/guide/examples/bool-select/)
- [`gallery/class-builder/class-builder.shade.ts`](https://typeshade.dev/guide/examples/class-builder/)
- [`gallery/class-parts/class-parts.shade.ts`](https://typeshade.dev/guide/examples/class-parts/)
- [`gallery/class-syntax/class-syntax.shade.ts`](https://typeshade.dev/guide/examples/class-syntax/)
- [`gallery/closures/closures.shade.ts`](https://typeshade.dev/guide/examples/closures/)
- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/guide/examples/cube-array-gather/)
- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/guide/examples/cube-env/)
- [`gallery/cutout/cutout.shade.ts`](https://typeshade.dev/guide/examples/cutout/)
- [`gallery/default-args/default-args.shade.ts`](https://typeshade.dev/guide/examples/default-args/)
- [`gallery/feedback-trail/feedback-trail.shade.ts`](https://typeshade.dev/guide/examples/feedback-trail/)
- [`gallery/generic-class/generic-class.shade.ts`](https://typeshade.dev/guide/examples/generic-class/)
- [`gallery/generic-helpers/generic-helpers.shade.ts`](https://typeshade.dev/guide/examples/generic-helpers/)
- [`gallery/higher-order/higher-order.shade.ts`](https://typeshade.dev/guide/examples/higher-order/)
- [`gallery/imported-noise/imported-noise.shade.ts`](https://typeshade.dev/guide/examples/imported-noise/)
- [`gallery/inferred-returns/inferred-returns.shade.ts`](https://typeshade.dev/guide/examples/inferred-returns/)
- [`gallery/mixin-surface/mixin-surface.shade.ts`](https://typeshade.dev/guide/examples/mixin-surface/)
- [`gallery/normal-matrix/normal-matrix.shade.ts`](https://typeshade.dev/guide/examples/normal-matrix/)
- [`gallery/null-values/null-values.shade.ts`](https://typeshade.dev/guide/examples/null-values/)
- [`gallery/packing-bitcast/packing-bitcast.shade.ts`](https://typeshade.dev/guide/examples/packing-bitcast/)
- [`gallery/palette-const/palette-const.shade.ts`](https://typeshade.dev/guide/examples/palette-const/)
- [`gallery/pick-composite/pick-composite.shade.ts`](https://typeshade.dev/guide/examples/pick-composite/)
- [`gallery/ray-class/ray-class.shade.ts`](https://typeshade.dev/guide/examples/ray-class/)
- [`gallery/rng-method/rng-method.shade.ts`](https://typeshade.dev/guide/examples/rng-method/)
- [`gallery/separable-blur/separable-blur.shade.ts`](https://typeshade.dev/guide/examples/separable-blur/)
- [`gallery/shape-inheritance/shape-inheritance.shade.ts`](https://typeshade.dev/guide/examples/shape-inheritance/)
- [`gallery/textured-quad/textured-quad.shade.ts`](https://typeshade.dev/guide/examples/textured-quad/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [`vec3()` in `typeshade/core/ir`](https://typeshade.dev/api/vec3/)
