GLSL built-in function

textureGrad()

Supplies explicit x/y coordinate gradients for texture filtering.

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

Syntax

gvec4 textureGrad(gsampler2D sampler, vec2 coord, vec2 dx, vec2 dy)

Parameters

sampler
Bound fixture texture
coord
Lookup coordinate
dx
Coordinate gradient along screen x
dy
Coordinate gradient along screen y

Return value

Four filtered components sampled with the supplied x and y coordinate gradients controlling the footprint.

Live example

Edit the code and the preview updates as you type.

What textureGrad does

Supplies explicit x/y coordinate gradients for texture filtering.

Read the preview

exp2(u_parameter*7.0)/256.0 sets the lookup footprint rather than moving uv. Set the parameter to 0 for a roughly one-texel footprint, then to 1 for much coarser filtering.

Core call

textureGrad(u_texture,uv,vec2(exp2(u_parameter*7.0)/256.0,0),vec2(0,exp2(u_parameter*7.0)/256.0)).rgb;

Gradients describe the texture-coordinate footprint of one screen pixel, not a color gradient.

Experiment

Replace both u_parameter*7.0 expressions with 4.0. The footprint stays at 16 texels regardless of the slider, keeping the grid blurred at one fixed scale.

Specification

GLSL ES 3.00 built-in functions, chapter 8

Related functions