---
title: "textureLoad / texelFetch: WGSL and GLSL function guide"
description: "A texel load reads one stored value at integer coordinates, without sampler interpolation."
url: https://typeshade.dev/reference/functions/textureLoad/
language: en
---

# `textureLoad`

Function

A texel load reads one stored value at integer coordinates, without sampler interpolation.

**Related names in other languages**

These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.

- GLSL: `texelFetch`
- GLSL: `imageLoad`

[Targets](https://typeshade.dev/reference/functions/textureLoad/#targets)

## Compare examples

Compare the integer coordinates with the selected cell. No neighbouring values are blended.

**Model assumptions**`texture_2d<f32>; level = 0`

**Example 1`textureLoad(tex, vec2i(0, 0), 0).r`**

`0.75` `1` `0` `0.25`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Result**

`0`

**Example 2`textureLoad(tex, vec2i(1, 0), 0).r`**

`0.75` `1` `0` `0.25`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Result**

`0.25`

**Example 3`textureLoad(tex, vec2i(1, 1), 0).r`**

`0.75` `1` `0` `0.25`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Result**

`1`

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 exact lookup in image-processing kernels, lookup tables, and multisample inspection.

## Inputs and limits

The example reads an in-bounds base-mip texel. Multisampled textures take a sample index instead of a mip level. Keep coordinates in bounds.

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

- [`textureSample`](https://typeshade.dev/reference/functions/textureSample/)
- [`textureSampleLevel`](https://typeshade.dev/reference/functions/textureSampleLevel/)
- [`textureSampleBias`](https://typeshade.dev/reference/functions/textureSampleBias/)
- [`textureSampleGrad`](https://typeshade.dev/reference/functions/textureSampleGrad/)
- [`textureGather`](https://typeshade.dev/reference/functions/textureGather/)

**WGSL**

`textureLoad(a, b, c)`

**GLSL ES 3.00**

`texelFetch(a, b, int(c))`

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

Reads one texel at the integer `coord` and mip `level` without filtering, by a `vec2i` on a `texture_2d`, a `vec3i` on a `texture_3d` and one integer on a `texture_1d`; a cube texture has no texel fetch on either target.

## Syntax

```ts
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_2d<E>,
  coord: TexelCoord2,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_2d_array<E>,
  coord: TexelCoord2,
  layer: number,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_3d<E>,
  coord: TexelCoord3,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_1d<E>,
  coord: number,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_multisampled_2d<E>,
  coord: TexelCoord2,
  sampleIndex: number,
): Vec4OfElem<E>
declare function textureLoad(tex: texture_depth_multisampled_2d, coord: TexelCoord2, sampleIndex: number): f32
declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>(
  tex: texture_storage_2d<F, A>,
  coord: TexelCoord2,
): StorageTexel<F>
declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>(
  tex: texture_storage_2d_array<F, A>,
  coord: TexelCoord2,
  layer: number,
): StorageTexel<F>
```

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.

**`TextureElem`**

`type TextureElem = f32 | i32 | u32`

**`Vec4OfElem`**

`type Vec4OfElem<E> = typeof u32Tag extends keyof E ? vec4u : typeof i32Tag extends keyof E ? vec4i : vec4`

**`TexelCoord2`**

`type TexelCoord2 = vec2i | vec2u`

**`TexelCoord3`**

`type TexelCoord3 = vec3i | vec3u`

**`StorageFormat`**

`type StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'`

**`StorageTexel`**

``type StorageTexel<F extends StorageFormat> = F extends `${string}uint` ? vec4u : F extends `${string}sint` ? vec4i : vec4``

## Parameters

- `tex` `texture_2d<E>``texture_2d_array<E>``texture_3d<E>``texture_1d<E>``texture_multisampled_2d<E>``texture_depth_multisampled_2d``texture_storage_2d<F, A>``texture_storage_2d_array<F, A>`
- `coord` `TexelCoord2``TexelCoord3``number`
- `level` optional `number`
- `layer` optional `number`
- `sampleIndex` optional `number`

## Return value

`Vec4OfElem<E>``f32``StorageTexel<F>`

## Description

On a `texture_2d_array` the layer comes before the level, and on a `texture_multisampled_2d` or `texture_depth_multisampled_2d` the third argument is the sample index instead of a level. Compiles to `textureLoad` on WGSL and `texelFetch` on GLSL, where the lowering of a multisampled texture is not supported yet ([Rule 10.5](https://typeshade.dev/reference/rules/10-5/)), so a module loading one emits WGSL alone.

The CPU oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with `{ gpuStubs: true }`, which returns a placeholder.

## Targets

**WGSL**

`textureLoad(a, b, c)`

**GLSL ES 3.00**

`texelFetch(a, b, int(c))`

An author writes the same call on every texture, and the compiler writes what each target needs. GLSL ES 3.00's `texelFetch` takes a signed coordinate, carries an array layer inside it and has no 1d or multisampled texture.

Texture You write WGSL GLSL ES 3.00

```wgsl
texture_2d<f32>
```

```ts
textureLoad(t, vec2i(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 0u)
```

```glsl
texelFetch(t, ivec2(1, 2), int(0u))
```

```wgsl
texture_2d<f32>
```

```ts
textureLoad(t, vec2u(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<u32>(1u, 2u), 0u)
```

```glsl
texelFetch(t, ivec2(uvec2(1u, 2u)), int(0u))
```

```wgsl
texture_3d<f32>
```

```ts
textureLoad(t, vec3i(1, 2, 3), 0)
```

```wgsl
textureLoad(t, vec3<i32>(1, 2, 3), 0u)
```

```glsl
texelFetch(t, ivec3(1, 2, 3), int(0u))
```

```wgsl
texture_3d<f32>
```

```ts
textureLoad(t, vec3u(1, 2, 3), 0)
```

```wgsl
textureLoad(t, vec3<u32>(1u, 2u, 3u), 0u)
```

```glsl
texelFetch(t, ivec3(uvec3(1u, 2u, 3u)), int(0u))
```

```wgsl
texture_2d_array<f32>
```

```ts
textureLoad(t, vec2i(1, 2), 3, 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 3, 0u)
```

```glsl
texelFetch(t, ivec3(ivec2(1, 2), int(3)), int(0u))
```

```wgsl
texture_2d_array<f32>
```

```ts
textureLoad(t, vec2u(1, 2), 3, 0)
```

```wgsl
textureLoad(t, vec2<u32>(1u, 2u), 3, 0u)
```

```glsl
texelFetch(t, ivec3(ivec2(uvec2(1u, 2u)), int(3)), int(0u))
```

```wgsl
texture_1d<f32>
```

```ts
textureLoad(t, 1, 0)
```

```wgsl
textureLoad(t, 1, 0u)
```

No form on this target.

```wgsl
texture_multisampled_2d<f32>
```

```ts
textureLoad(t, vec2i(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 0u)
```

No form on this target.

```wgsl
texture_depth_multisampled_2d
```

```ts
textureLoad(t, vec2i(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 0u)
```

No form on this target.

## Examples

- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/guide/examples/cube-env/)
- [`gallery/feedback-trail/feedback-trail.shade.ts`](https://typeshade.dev/guide/examples/feedback-trail/)
- [`gallery/kernel-image-invert/kernel-image-invert.shade.ts`](https://typeshade.dev/guide/examples/kernel-image-invert/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/guide/examples/msaa-resolve/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/guide/examples/storage-texture/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#textures)
- [`textureLoad()` in `typeshade/core/ir`](https://typeshade.dev/api/textureload/)
