---
title: "uniform(): function in Runtime, TypeShade API reference"
description: "uniform, a function in Runtime. A uniform of the struct of cls, a class a shader module exports: one range of the region, zeroed…"
url: https://typeshade.dev/api/uniform/
language: en
---

# `uniform()`

Function in Runtime

A uniform of the struct of cls, a class a shader module exports: one range of the region, zeroed, then given the fields init names.

`import { uniform } from 'typeshade/runtime'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function uniform<T extends object>(
  cls: ResourceClass<T, 'set' | 'needsUpdate' | 'dispose'>,
  init?: Some<T>,
): Uniform<T>
```

## Parameters

**`cls` `ResourceClass<T, 'set' | 'needsUpdate' | 'dispose'>`**

**`init` optional `Some<T>`**

some of its fields, each a host value ([Rule 8.21](https://typeshade.dev/reference/rules/8-21/)).

## Return value

`Uniform<T>`

the uniform, whose fields are set with `set` and read with `get`.

## Exceptions

**`TypeError`**

`TypeError` for a value that is no class of a shader module, for an abstract class, for a struct with no uniform layout (a `bool`, a two-row matrix), for a field whose name is the accessor’s own (`set`, `needsUpdate`, `dispose`), and for an `init` that does not fit. The host’s editor refuses a class with such a field already, with [`TS8079`](https://typeshade.dev/reference/errors/ts8079/) (Amendment A5, D3).

## Description

`uniform<T>` in a shader file and `uniform(T)` in host code name the same thing, a uniform of `T` (Amendment A1).

## In the guide

- [Language guide](https://typeshade.dev/guide/internals/)
- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)
- [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/)

## See also

- [`uniformStruct`](https://typeshade.dev/api/uniformstruct/)
- [`storageBuffer`](https://typeshade.dev/api/storagebuffer/)

## Source

[`src/runtime/resource.ts`, line 1014](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/resource.ts#L1014), at commit af54ddad5
