dither

Get an element of the Bayer dithering matrix normalized to the range (0, 1).

template <ORDER>
float dither(ivec2 pos);

ORDER specifies the size of the matrix (2^order × 2^order) and must be between 0 and 15. For example, ORDER 4 yields a 16×16 matrix with 256 different values.

Example

The most common use is eliminating stripes in color gradients by adding dithering in the range of 1/256 for the 32-bit color model:

color += (1.0/256.0)*(dither<4>(ivec2(gl_FragCoord.xy))-0.5);