GLSL built-in function

textureOffset()

Performs a filtered texture lookup with a constant texel offset.

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

Syntax

gvec4 textureOffset(gsampler2D sampler, vec2 coord, ivec2 offset)

Parameters

sampler
Bound fixture texture
coord
Lookup coordinate
offset
Compile-time constant texel offset

Return value

Four filtered components from coord plus a constant texel offset, with the mip footprint selected implicitly.

Live example

Edit the code and the preview updates as you type.

What textureOffset does

Performs a filtered texture lookup with a constant texel offset.

Read the preview

textureOffset(u_texture,uv,ivec2(3,0)) shifts the grid's sample position three texels horizontally at the sampled level. Use ivec2(0,0) for the unshifted reference image.

Core call

textureOffset(u_texture,uv,ivec2(3,0)).rgb;

The offset is in texels, not UV units; it cannot be a uniform expression.

Experiment

Change the last argument to ivec2(-3,0). The letters move in the opposite screen direction; this changes lookup position rather than rotating or recoloring the image.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions