---
title: "uniform: shader function examples, uses and input limits"
description: "A uniform declaration describes data supplied by the host and shared by shader invocations during a draw or dispatch."
url: https://typeshade.dev/reference/functions/uniform/
language: en
---

# `uniform`

Function

A uniform declaration describes data supplied by the host and shared by shader invocations during a draw or dispatch.

## Compare examples

The shader reads the parameter value supplied by the host. Declaring a uniform does not upload the value.

**Model assumptions**`class Params { scale: f32; } declare const u: uniform<Params>;`

**Example 1`host: u.scale = 1; shader: u.scale`**

**Result**

`1`

**Example 2`host: u.scale = 2; shader: u.scale`**

**Result**

`2`

**Example 3`host: u.scale = 0; shader: u.scale`**

**Result**

`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 it for passing camera settings, dimensions, and other small parameters.

## Inputs and limits

The declaration does not upload data. The host must allocate, bind, and populate a buffer with the reflected layout. Shaders cannot write a uniform binding.

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

- [`storage`](https://typeshade.dev/reference/functions/storage/)
- [`array`](https://typeshade.dev/reference/functions/array/)

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

Declares a uniform binding of type T; use `declare const name: uniform<T>` or `const name = uniform<T>()`.

## Syntax

```ts
declare function uniform<T>(slot?: number | { group?: number; binding?: number }, binding?: number): ReadView<T>
```

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.

**`ReadView`**

`type ReadView<T> = T extends number | boolean ? T : T extends (...args: never[]) => unknown ? T : { readonly [K in keyof T]: K extends string | number ? ReadView<T[K]> : T[K] }`

## Parameters

- `slot` optional `number | { group?: number; binding?: number }`
- `binding` optional `number`

## Return value

`ReadView<T>`

## Examples

- [`path/uv-gradient/uv-gradient.shade.ts`](https://typeshade.dev/guide/examples/uv-gradient/)
- [`path/moving-wave/moving-wave.shade.ts`](https://typeshade.dev/guide/examples/moving-wave/)
- [`path/sdf-shapes/sdf-shapes.shade.ts`](https://typeshade.dev/guide/examples/sdf-shapes/)
- [`path/tile-pattern/tile-pattern.shade.ts`](https://typeshade.dev/guide/examples/tile-pattern/)
- [`path/fractal/fractal.shade.ts`](https://typeshade.dev/guide/examples/fractal/)
- [`path/palette/palette.shade.ts`](https://typeshade.dev/guide/examples/palette/)
- [`path/bouncing-balls/bouncing-balls.shade.ts`](https://typeshade.dev/guide/examples/bouncing-balls/)
- [`path/image-blur/image-blur.shade.ts`](https://typeshade.dev/guide/examples/image-blur/)
- [`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-deep-zoom-twin/fp64-deep-zoom-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-deep-zoom-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/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/guide/examples/bit-bump/)
- [`gallery/clip-planes/clip-planes.shade.ts`](https://typeshade.dev/guide/examples/clip-planes/)
- [`gallery/compute-reduction-twin/compute-reduction-twin.shade.ts`](https://typeshade.dev/guide/examples/compute-reduction-twin/)
- [`gallery/gradient-twin/gradient-twin.shade.ts`](https://typeshade.dev/guide/examples/gradient-twin/)
- [`gallery/hello-camera/hello-camera.shade.ts`](https://typeshade.dev/guide/examples/hello-camera/)
- [`gallery/hello-uniform/hello-uniform.shade.ts`](https://typeshade.dev/guide/examples/hello-uniform/)
- [`gallery/hello-uniform-struct/hello-uniform-struct.shade.ts`](https://typeshade.dev/guide/examples/hello-uniform-struct/)
- [`gallery/imported-noise/imported-noise.shade.ts`](https://typeshade.dev/guide/examples/imported-noise/)
- [`gallery/integer-math/integer-math.shade.ts`](https://typeshade.dev/guide/examples/integer-math/)
- [`gallery/loops-over-data/loops-over-data.shade.ts`](https://typeshade.dev/guide/examples/loops-over-data/)
- [`gallery/normal-matrix/normal-matrix.shade.ts`](https://typeshade.dev/guide/examples/normal-matrix/)
- [`gallery/packed-bytes/packed-bytes.shade.ts`](https://typeshade.dev/guide/examples/packed-bytes/)
- [`gallery/particle-step/particle-step.shade.ts`](https://typeshade.dev/guide/examples/particle-step/)
- [`gallery/sample-branch/sample-branch.shade.ts`](https://typeshade.dev/guide/examples/sample-branch/)
- [`gallery/separable-blur/separable-blur.shade.ts`](https://typeshade.dev/guide/examples/separable-blur/)
- [`gallery/uniform-array/uniform-array.shade.ts`](https://typeshade.dev/guide/examples/uniform-array/)
- [`gallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts`](https://typeshade.dev/guide/examples/workgroup-tile-2d/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
