JavaScript EditorFree JavaScript Editor     Ajax Editor 



Main Page
Previous Page
Next Page

5.8. Fragment Processing Functions

Fragment processing functions are only available in shaders intended for use on the fragment processor. This category has three built-in functions. Two obtain derivatives and the other estimates the filter width used to antialias procedural textures.

The derivative functions, dFdx and dFdy, determine the rate of change of an expression. The function dFdx(p) evaluates the derivative of the expression p in the x direction in window coordinates, and the function dFdy(p) evaluates the derivative of the expression p in the y direction in window coordinates. These values indicate how fast the expression is changing in window space, and this information can be used to take steps to prevent aliasing. For instance, if texture coordinates are changing rapidly, it may be better to set the resulting color to the average color for the texture in order to avoid aliasing.

It only makes sense to apply these functions to expressions that vary from one fragment to the next. Because the value of a uniform variable does not change from one pixel to the next, its derivative in x and in y is always 0. See Table 5.8.

Table 5.8. Fragment Processing Functions

Syntax

Description

float dFdx (float p)
vec2 dFdx (vec2 p)
vec3 dFdx (vec3 p)
vec4 dFdx (vec4 p)

Returns the derivative in x for the input argument p.

float dFdy (float p)
vec2 dFdy (vec2 p)
vec3 dFdy (vec3 p)
vec4 dFdy (vec4 p)

Returns the derivative in y for the input argument p.

float fwidth (float p)
vec2 fwidth (vec2 p)
vec3 fwidth (vec3 p)
vec4 fwidth (vec4 p)

Returns the sum of the absolute derivative in x and y for the input argument p, i.e.,
return = abs (dFdx (p)) + abs (dFdy (p));



Previous Page
Next Page




JavaScript EditorAjax Editor     JavaScript Editor