GLSL built-in function

texelFetchOffset()

Fetches a texel with an additional constant integer offset.

Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment

Syntax

gvec4 texelFetchOffset(gsampler2D sampler, ivec2 coord, int lod, ivec2 offset)

Parameters

sampler
Bound fixture texture
coord
Lookup coordinate
lod
Mip level; zero is full resolution
offset
Compile-time constant texel offset

Return value

The four components of the texel at coord + offset in the selected mip level, without interpolation.

Live example

Edit the code and the preview updates as you type.

What texelFetchOffset does

Fetches a texel with an additional constant integer offset.

Read the preview

The base address ivec2(uv*251.0)+ivec2(2) leaves room for the constant ivec2(1,0) offset. Change that offset to ivec2(-1,0) to read two texels farther left while remaining in bounds.

Core call

texelFetchOffset(u_texture,ivec2(uv*251.0)+ivec2(2),0,ivec2(1,0)).rgb;

offset must be a constant expression within the implementation limits.

Experiment

Set the final offset argument to ivec2(0,1). Sampling moves from the right neighbor to the upper neighbor of the base address, which shifts the grid's registration on screen.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions