So much for the "alpha" parameter. Now for the final parameter, and the most fun and versatile of them all: the output parameter "g" that returns the gradient of the noise function.
Note that this is the analytical gradient. It is an exact derivative, to the limit of the working precision of the GPU, and it requires a lot less work to compute than performing several additional function calls and computing a finite difference approximation. (That "d" in the name "psrdnoise" is short for "with derivatives")
This visualisation shows the gradients at certain points as vectors overlaid on the noise pattern. The image doesn't really say a lot, but next we'll create an animated version that will make more sense. (Also, it was a fun challenge to make a fragment shader draw little arrows.) Note that, despite what this particular image might suggest, the gradient is computed at every point that is evaluated by the fragment shader, with only a small amount of extra work.
If you don't need the value of the gradient for anything, leaving the output parameter "g" unused in your shader will make the GLSL compiler eliminate the "dead code" for computing it, which speeds up the function by around 15%.
If you are curious, feel free to look at the function "vectorfield" in the source code. It's a bit more complicated than "gridpoints" and "gridlines", but it follows the same general principle of drawing anti-aliased implicit shapes by thresholding combinations of carefully chosen distance functions.
(And, if you didn't quite understand that last paragraph, don't worry. Drawing these little arrows is a totally different thing from using noise to make good looking patterns.)
// Text in this pane will be dynamically replaced.