Intrinsics1 min read

gather_offset

Gathers four texel values from an offset 2x2 footprint.

Reading Time
1 min
Word Count
120
Sections
7
Try It Live

Test gather_offset in a live shader

Open the playground, start from a visual preset, and wire gather_offset into the fragment stage to see how it behaves with real values.

Open Playground

The gather_offset function gathers one component from four texels in a 2x2 footprint after applying an integer texel offset to the lookup location.

Live Demo

Signature

bwsl
gather_offset :: (texture2D tex, sampler samp, float2 uv, int component, int2 offset) -> float4 {...}

Parameters

ParameterTypeDescription
textexture2DTexture to gather from
sampsamplerSampler state
uvfloat2Texture coordinates
componentintComponent to gather, where 0=R, 1=G, 2=B, 3=A
offsetint2Integer texel offset applied to the gather footprint

Return Value

Returns a float4 containing the selected component from the offset 2x2 texel footprint.

Example

bwsl
float4 center = gather(heightMap, uv, 0);
float4 right = gather_offset(heightMap, uv, 0, int2(1, 0));

Compiled Output

When compiled to GLSL:

glsl
textureGatherOffset(tex, uv, offset, component)

See Also