textureGather
On this page

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 assumptionschannel = 0; uv = vec2(0.5, 0.5); level = 0

Example 1textureGather(0, tex, smp, uv)
0.75100.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 2textureGather(0, tex, smp, uv)
1001
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 3textureGather(0, tex, smp, uv)
0.50.50.50.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 and GLSL ES 3.00.

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

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

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), so a module using it emits WGSL alone.

Targets

WGSL
textureGather(a, b, c, d)
GLSL ES 3.00
textureGather is not supported yet on the WebGL2 tier (Rule 10.5)

Examples

See also

Edit this page Report a problem