---
title: "textureGather: shader function examples and input limits"
description: "Gather returns one channel from the four texels around a sampling coordinate without blending them into one value."
url: https://typeshade.dev/reference/functions/textureGather/
language: en
---

# `textureGather`

Function

Gather returns one channel from the four texels around a sampling coordinate without blending them into one value.

## Compare examples

Follow the output order around the grid: upper left, upper right, lower right, lower left.

**Model assumptions**`channel = 0; uv = vec2(0.5, 0.5); level = 0`

**Example 1`textureGather(0, tex, smp, uv)`**

`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**

`vec4(0.75, 1, 0.25, 0)`

**Example 2`textureGather(0, tex, smp, uv)`**

`1` `0` `0` `1`

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

**Result**

`vec4(1, 0, 1, 0)`

**Example 3`textureGather(0, tex, smp, uv)`**

`0.5` `0.5` `0.5` `0.5`

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

**Result**

`vec4(0.5, 0.5, 0.5, 0.5)`

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 to implement a custom image filter that needs individual neighbouring samples.

## Inputs and limits

This model gathers an interior base-mip neighbourhood. Colour textures require a literal channel selector. Gather is WebGPU-only in this compiler target pair.

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/)
- [`textureLoad`](https://typeshade.dev/reference/functions/textureLoad/)
- [`textureSampleLevel`](https://typeshade.dev/reference/functions/textureSampleLevel/)
- [`textureSampleBias`](https://typeshade.dev/reference/functions/textureSampleBias/)
- [`textureSampleGrad`](https://typeshade.dev/reference/functions/textureSampleGrad/)

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

Reads one channel from the four texels a linear filter would blend at the coordinate on mip level 0, through the sampler `smp`, and returns them as a `vec4` in the order (umin,vmax), (umax,vmax), (umax,vmin), (umin,vmin), in any stage.

## Syntax

```ts
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_2d<E>,
  smp: sampler,
  uv: vec2,
): Vec4OfElem<E>
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_2d_array<E>,
  smp: sampler,
  uv: vec2,
  layer: number,
): Vec4OfElem<E>
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_cube<E>,
  smp: sampler,
  dir: vec3,
): Vec4OfElem<E>
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_cube_array<E>,
  smp: sampler,
  dir: vec3,
  layer: number,
): Vec4OfElem<E>
declare function textureGather(tex: texture_depth_2d, smp: sampler, uv: vec2): vec4
declare function textureGather(tex: texture_depth_2d_array, smp: sampler, uv: vec2, layer: number): vec4
declare function textureGather(tex: texture_depth_cube, smp: sampler, dir: vec3): vec4
declare function textureGather(tex: texture_depth_cube_array, smp: sampler, dir: vec3, layer: number): vec4
```

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`

## Parameters

- `component` optional `number`
- `tex` `texture_2d<E>``texture_2d_array<E>``texture_cube<E>``texture_cube_array<E>``texture_depth_2d``texture_depth_2d_array``texture_depth_cube``texture_depth_cube_array`
- `smp` `sampler`
- `uv` optional `vec2`
- `dir` optional `vec3`
- `layer` optional `number`

## Return value

`Vec4OfElem<E>``vec4`

## Description

On a colour texture the first argument is the channel, a whole number from 0 to 3 written in the call; a depth texture has one channel and takes none; an array texture takes the layer after the coordinate. Compiles to `textureGather` on WGSL; its GLSL lowering is not supported yet ([Rule 10.5](https://typeshade.dev/reference/rules/10-5/)), so a module using it 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**

`textureGather(a, b, c, d)`

**GLSL ES 3.00**

`textureGather` is not supported yet on the WebGL2 tier (Rule 10.5)

## Examples

- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/guide/examples/cube-array-gather/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#textures)
