I don't know any good place from where to learn all the material, but I can try to give you a few pointers. The following comes with the caveat that I only dabbled in writing shaders a bit and am certainly no expert on this topic.
Abstractly, a functional shader is given by a function f: R → [0,1]³, where R is some subset of ℝ² (usually a rectangle) and [0,1]³ is interpreted as the space of all RGB colors. So f assigns each point of the shaded region a color. Your job is to provide f. Then, each time the image is rendered the viewer evaluates f on (the point of R corresponding to) each pixel inside the image and colors the pixel with the returned color.
In PGF, you'd specify such a function with \pgfdeclareshading
:
\pgfdeclarefunctionalshading
{⟨shading name⟩}
{⟨lower left corner⟩}{⟨upper right corner⟩}
{⟨initialization code⟩}
{⟨code for the actual shading⟩}
Here {⟨lower left corner⟩}{⟨upper right corner⟩}
specifies the rectangular domain R ⊆ ℝ², ⟨initialization code⟩
can be ignored for the moment (see the PGF manual for details) and ⟨code for the actual shading⟩
is the difficult part.
The actual code for the shading has to be written in a very restricted subset of PostScript. Presumably it is so restricted to force you to only write very simple function. Even so, be aware that the rendering of a shading can take a very long time (and has to be done each time the document is displayed).
PostScript is a stack-based programming language. If you are not familiar with this concept, try reading the Wikipedia article on that subject. If you are not used to stack-based languages, be aware that writing even very simple functions can be a challenge.
The allowed subset is listed in the PGF manual or the PDF reference: basically you only have math functions, stack manipulation operators and if-then-else at your disposal. You'll notice that there are no loops and variables. The operations themselves are described in section 3.6 of the Postscript Language Reference 3rd Edition or presumably any other good book about PostScript (see for example Wikipedia's references).
At the start of the execution of the shader function the stack consists of the x and y coordinate of a point in R (in big points) and after the execution the top three stack elements should be real values in [0,1] which are treated as red, green and blue component of the color of this point.
These shadings are the least portable of all and they put the heaviest burden of the renderer. They are slow and, possibly, will not print correctly!
). Maybe you could explain what you are trying to achieve so people might suggest other avenues to explore.r=0
. What value do you want to assign to red, what value to blue? What do you want to do nearr=0
?