The ability to take derivatives of functions relative to screen-space position is important for shader antialiasing. Sh offers functions to compute derivatives of any value with respect to screen-space derivatives, but these can only be used inside a fragment shader. Also, derivatives may be approximated with differences on some platforms (or, unfortunately, may be unavailable). A summary of the derivative functions is provided in Table 3.5.
/ The dx and dy functions compute the derivative of their argument with
respect to screen-space position x and y respectively. If an n-tuple is given as an
argument, an n-tuple is returned, with each component being the derivative of
the corresponding component in the input. The jacobian function computes a
matrix. The first row is basically the result of applying dx to the input, the
second row the result of dy applied to the input. The fwidth function computes
the componentwise maximum of the absolute values of dx and dy. This is the
usual rule used to select a MIP-map level in a texture. Finally, the gradient
function only takes a scalar as an argument, and returns a 2-tuple which is the
result of taking the derivative of the provided quantity in the x and y
directions.
|
Note: This manual is available as a bound book from AK Peters, including better formatting, in-depth examples, and about 200 pages not available on-line.