---
title: "TypeShade GPU types"
description: "How TypeScript type syntax maps to TypeShade scalar, vector, matrix and array GPU values."
url: https://typeshade.dev/guide/language/gpu-types/
language: en
---

# GPU types: from TypeScript syntax to GPU values

TypeShade uses TypeScript syntax but does not inherit every JavaScript runtime value type as a shader value. This page focuses on the values that are actually represented and computed on the GPU.

## 1. TypeScript types and GPU types

A `number` written as a type is inferred from its uses, so the compiler picks the GPU representation. `f32`, `i32` and `u32` fix a width when you want to choose it. `vec*` and `mat*` are GPU arithmetic values, not JavaScript objects.

```ts
// TypeScript surface, GPU-specific value types
let value: f32 = 1
let index: u32 = 0
let direction: vec3 = vec3(0, 1, 0)
```

## 2. Scalars

Single numeric values are represented as GPU scalar types and can be used in resource and struct field declarations.

Learn what `precision highp float;` means, compare stage defaults, and inspect browser capabilities in the [GLSL precision guide](https://typeshade.dev/guide/concepts/glsl-precision/).

## 3. Vectors

`vec2`, `vec3` and `vec4` group scalar values into a GPU value. They are common in shader calculations and stage inputs.

```ts
const uv: vec2 = vec2(0.5, 0.5)
const color: vec4 = vec4(1, 0, 0, 1)
```

## 4. Matrices

Types such as `mat4` represent GPU arithmetic values used for transforms. They are not JavaScript objects.

```ts
type Camera = {
  view: mat4
}
```

## 5. Arrays

An array represents a sequence of GPU values. Fixed-length arrays and homogeneous tuples support local const and let binding patterns, including omitted and nested elements. Each binding copies a value. Runtime-sized and specialization-sized arrays do not support these patterns. Combined with a resource element type, an array describes host-provided buffer data.

```ts
declare const pixels: storage<array<f32>, "read_write">
```

## 6. Live example

The entry below names a GPU type on every line: `vec2` for the position, `f32` for the distance and the radius, `vec3` for the colour.

disc.shade.ts

```ts
"use typeshade"

class Uniforms {
  resolution: vec2
  center: vec2
  radius: f32
  tint: vec3
}

declare const u: uniform<Uniforms>

@fragment
export function main(uv: location<0, vec2>): vec4 {
  const ratio: f32 = u.resolution.x / u.resolution.y
  const p: vec2 = (uv - u.center) * vec2(ratio, 1.)
  const d: f32 = length(p) - u.radius
  const edge: f32 = 1. - smoothstep(0., 0.008, d)
  return vec4(mix(vec3(0.15, 0.14, 0.91), u.tint, edge), 1.)
}
```

[Open in the Playground](https://typeshade.dev/playground/)

![Disc shader, written in TypeScript and compiled by TypeShade, rendered at build time.](https://typeshade.dev/stills/gpu-types-disc.webp)

A disc placed by a `vec2`, sized by an `f32` and coloured by a `vec3`.

`d` is the distance from the pixel to the rim of the disc: negative inside it, 0 on the rim, positive outside. `edge` turns that one `f32` into a mask, and `mix` reads the mask to pick a colour.

Filled by the page every frame, with no control: `resolution`.

Try the following, with the controls or by editing a line:

- Change `vec2(ratio, 1.)` to `vec2(1., 1.)` on the `p` line. The disc stretches into an ellipse: `ratio` was scaling the x component alone, which is what a `vec2` lets you do.
- Replace the `return` line with `return vec4(vec3(fract(d * 10.)), 1.)`. The rings that appear are `d` itself, and `vec3` spreads that one `f32` across the three colour channels.
- Swap `length(p)` for `max(abs(p.x), abs(p.y))` and the disc becomes a square, or for `abs(p.x) + abs(p.y)` and it becomes a diamond. Then write the `f32` for a shape of your own.

[Next: Functions](https://typeshade.dev/guide/language/functions/)
