GL_OES_standard_derivatives

Supported Hardware

Series5, Series5XT, Series6, Series6XE, Series6XT

Valid APIs

OpenGL ES 2.0

Description

Standard derivative functions are optionally available in the GL shading language to give an approximate delta to the values in neighbouring fragments in the x or y directions. The function will evaluate the local difference for any value passed to it. It uses dFdx() to return the difference in the x direction, and dFdy() to return the difference in the y direction.

For example, if you were to call ‘dFdx(gl_FragCoord.x)’, you’d get a result of 1.0, as the neighbouring fragment will have an x coordinate exactly one position over. ‘dFdx(gl_FragCoord.y)’ on the other hand would return 0.0, as the y coordinate is static as you move left or right.

Typical use of this functionality is to estimate the filter width used for anti-aliasing procedural textures. To facilitate this use case, a third function is provided: fwidth(), which returns the sum of the absolute difference in x and y (e.g. abs(dFdx(val)) + abs(dFdy(val))).

Note

This functionality is core to OpenGL ES 3.0.

Example

// Get the texture colour for a given fragment
lowp vec4 colourHere = texture2D(sTexture, TexCoord.xy);
// Get the value that was used in a neighbouring fragment in the x direction
lowp vec4 colourNextDoor = dFdx(colourHere) + colourHere;
// Get the value that was used in a neighbouring fragment in the y direction
lowp vec4 colourNextDoorVertically = dFdy(colourHere) + colourHere;