GLSL built-in function

textureGradOffset()

Combines explicit texture gradients with a constant offset.

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

Syntax

gvec4 textureGradOffset(gsampler2D sampler, vec2 coord, vec2 dx, vec2 dy, ivec2 offset)

Parameters

sampler
Bound fixture texture
coord
Lookup coordinate
dx
Coordinate gradient along screen x
dy
Coordinate gradient along screen y
offset
Compile-time constant texel offset

Return value

Four filtered components using explicit gradients and a constant integer texel offset in addition to coord.

Live example

Edit the code and the preview updates as you type.

What textureGradOffset does

Combines explicit texture gradients with a constant offset.

Read the preview

The .03 gradients blur the grid while ivec2(2,0) adds a horizontal texel offset. Change the offset to ivec2(0,0) to remove that displacement without changing blur.

Core call

textureGradOffset(u_texture,uv,vec2(.03,0),vec2(0,.03),ivec2(2,0)).rgb;

The constant offset is applied in texel units, not added as a raw UV value.

Experiment

Change both gradient magnitudes from .03 to .003, keeping ivec2(2,0). The lettering becomes sharper because the filter footprint shrinks, while the offset remains.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions