First a little bit of theoretical background before  discussing  the  shader
used for these experiments and the scenes that use it. It is provided simply
to help readers who are not familiar with complex numbers to understand  the
shader, and is very superficial.

=============================================================================

A complex number, conventionaly denoted by z,  may be regarded as having two
components,  x and y,  each of which is just an ordinary real number such as
1.63 or -7. Given two such components the complex number z is given by

        z = x + i*y

where i is the square root of -1.  The x component is known as the real part
and the y component as the imaginary part. It should be noted that a complex
is a single number and is best thought of as such rather than  as  shorthand
for its two components.

The real numbers can be considered as a subset of the complex numbers, those
for which the imaginary part, y, is zero. Likewise the imaginary numbers are
the subset of the complex numbers for which the real part, x, is zero.

Addition and multiplication then just use the normal rules for the  addition
and multiplication of pairs of sums, i.e.

     z1+z2 = (x1+i*y1) + (x2+i*y2)
           = x1+x2 + i*(y1+y2)

     z1*x2 = (x1+i*y1) * (x2+i*y2)
           = (x1*x2-y1*y2) + i*(x1*y2+x2*y1)

Division is more complex

     z1/z2 = (x1+i*x2) / (x2+i*y2)
           = ( (x1*x2+y1*y2) + (y1*x2-x1*y2) ) / (y1^2+y2^2)

where ^ is the exponentiation operator, i.e. a^b is the bth power of a.

Just these simple rules allow us to evaluate polynomial functions such as

     f(z) = z**3 + 2.5*z**2 + 7*z

and by analogy with functions of real variables more general  functions  can
be expressed using polynomial expansions,  though we do not use that here or
in the shader.  In general the relationships between functions that apply to
functions of simple real variables apply to functions of complex numbers, so
such things as

     sin(z)^2 + cos(z)^2 = 1.0   --   where 1.0 is 1.0 + i*0.0
     tan(z) = cos(z) / sin(z)

still hold.

An obvious interpretation of the x and y components of a complex  number  is
as the cartesian coordinates of a point in a plane, and this is how they are
generaly used in the shader.

However just as any point represented by a pair of cartesian coordinates can
also be represented by a pair of polar coordinates (r,theta) there is also a
second, polar, representation of complex numbers

    z = x + i*y = r * exp(i*theta)

where exp is the exponential function, r the distance from the origin of the 
point(x,y) and theta the angle measured at the origin from the x axis to the
(x,y) point. Note that x+i*y and r*exp(i*theta) are the same complex number,
but expressed in different ways.

The angle theta is often refered to as the phase, particularly in physics.

The polar representation of complex numbers is useful in many ways and often 
results in much simpler expressions for functions than would be the case  if
the cartesian representation were used.

=============================================================================

Drawing graphs of complex functions is itself complicated in that if we wish
to show the form of z' = f(z) we must deal with four components. Two are the
components of the domain of the function, z = x+i*y,  and two the components
of the result of the function, z' = x' + y'.  The problem is that we want to
show a two dimensional surface embedded in a four dimension  space,  and  we
need to do this on the two dimensional surface of computer screen.

If we consider the simpler problem of presenting a two  dimensional  surface
embedded in a three dimensional space,  e.g. the heights of an area of land,
the common solutions are

   Colour coding
   Contour lines
   A pseudo 3D view

In these experiments a combination of the first two of these are  used  with
colour coding being used for the theta component and contour lines for the r
compenent of complex results expressed in polar form, z=r*exp(i*theta).

As an enhancement to the above contour lines are drawn for the two cartesian
components of the function's results and optionaly for the theta component.

The shader used in these experiments can optional animate the display by the
simple mechanism of adding a time dependant phase, w*t, to theta. The effect
of this is to cause the colours used to indicate theta to rotate  about  one
or more  points in the image.

No support is provided for a pseudo 3D view, though it should be possible to
produce one by post processing the shader's output by another shader  rather
than displaying it directly.

=============================================================================

In most cases the functions supported by the shader are  "proper"  functions
of complex variables and as a result they produce  conformal  mappings  from
their domain to co-domain,   i.e. angles are preserved by the mapping though
lengths and areas are not. This can be seen in the output of the  shader  by
the x and y contours all crossing at right angles,  as   do  the r and theta
contours if both have been enabled. This assumes that the x and y scales are
equal,  which  need  not be the case if the pre or post scale factor control
parameters have been used to stretch the image more in  one  direction  than
the other.

The shader also supports a few "improper" functions for which the mapping is
not conformal.

=============================================================================

A complication arises because most functions of complex  variables  are  not
single valued.  Instead  of  a simple two dimensional surface such functions
should be represented by a series of "sheets" which are  connected  to  each
other in complicated ways. It is sometimes convenient to think of the sheets
introducing a fifth dimension,  sheet number,  with  the  sheets often being
connected in such a way as to form helices around one or  more  points  with 
the helices extending along this new dimension. The reality is somewhat more
complicated than that, for example a helix may connect back with itself when
it has completed one or more full turns, and doing this without intersecting
the two larger dimensional surface that it is just a part of.  Difficult  to
visualise,  but we are now considering a two dimensional surface embedded in
a higher dimensional space where such things are quite possible, just like a
closed loop can wrap around a point several times without crossing itself if
embedded in a three dimensional space but not in two dimensions.

The most common way to handle this complication,  and  that which is used by
the shader is to consider only one value, called the princple value,  of the
function at each point in its domain.  This  leaves  just one sheet which is
cut from its neihbours.  Such  cuts are normaly made along one of the x or y
axes,  usualy x,  but can in princple be made anywhere and do not have to be
straight.  Depending  on the function these cuts may be finite or may extend
to infinity in one direction and it is not uncommon for a pair  of  cuts  to
start from a single point, which is not itself part of the cut, and for both
to extend to infinity in opposite directions. In sich cases the single point
between the two cuts is the only connection between the two  halves  of  the
function's co-domain being shown.  The end points of the cuts,  about  which
surface seems to spiral in the sheet number direction,  are  called singular
points,  and  in  the animated versions of the images produced by the shader
the colours appear to be rotating around them with the cuts themselves being
seen as discontinuities in the colouring such as a jump from red to green.

There are other singular points,  such  as  poles where the function's value
becomes infinite, and the colouring will also be seen to rotate about these,
though as there is no asocciated cut the there will be no  discontinuity  in
the colouring as long as the ColourScale control has an integer value.

Finaly, the colours may also be seen to rotate about the domain's origin.

=============================================================================

The shader itself, TheEmu - Complex Functions.fsh, is highly configurable by
using control parameters declared as uniform variables which can be  defined
in the scene files using it.  These control parameters control the following
aspects of the  of the shader

   What function is to be evaluated and how long
   to display it before advancing to the next.

   What algorithm to use to colour the output.

   What contour lines are to be drawn and how
   sharp or fuzzy they should be.

This list is not complete and the comments in the shader  source  should  be
consulted for the full list and details of their use.

Note, currently there are two basic colourisation algorithms. The first is a
simple one as described above (and in more detail in the shader itself)  and
a second one that uses a texture input to the shader to  "tile"  the  output
with repetitions of the texture.  The  first  is  more "scientific" and most
clearly shows the structure of the function being evaluated while the second
shows how the function can be used to distort images and to create  "flows".

Although the first colourisation algorithm best shows the structure  of  the
function some aspects may be more apparent when using a  carefully  designed
texture and one such texture,  that previously used for the Experiments with
Tunnels, is provided.

=============================================================================
