Advanced functions

Custom depiction modes. By choosing “Customize...” from the menu you may modify the current depiction mode. In the appearing dialog you can change the code of the shader and also add an auxiliary texture. The shader has to be written in the OpenGL Shading Language Version 1.10. For example the “iteration” shader looks as follows:

vec4 color(Data data)
{
    vec3 c;
    if(data.iter>=0)
        c = pal(float(data.iter)+0.5, params.brightnessfinite/params.brightnessfactor);
    else
        c = pal(float(-data.iter)+0.5, params.brightnessinfinite/params.brightnessfactor);
    return vec4(c, 1.0);
}

Here is the code for the function “pal”:

vec3 pal(float iter, float brightness)
{
    vec3 c = vec3(0.0,0.0,0.0);
    for(int i=0;i<params.ncolor;i++)
    {
        float amplitude = 0.5*(1.0+sin(iter*params.color[i].frequency+params.color[i].initial));
        c += params.color[i].c*amplitude;
    }
    c*=brightness;
    float m = max(mac(c.r,c.g),c.b);
    if(m>1.0)c /= m;
    return c;
}

...and the specifications of the relevant structures:

typedef struct
{
    vec3 c;
    float frequency;
    float initial;
} UniformsColor;

typedef struct
{
    int ncolor;
    UniformsColor color[NCOLOR];
    float brightnessfinite;
    float brightnessinfinite;
    float brightnessfactor;
    float param[NPARAM];
    float time;
    int auxwidth;
    int auxheight;
} Params;

uniform Params params;

The number of custom parameters (Params.param[]) may be specified in the dialog. They can later be changed tapping on the “brush” icon in the lower right corner.
In the following structure members are only available and calculated if the corresponding slider is on. Keep in mind that any additional value may slow down the calculation.

typedef struct
{
    float dist;        // The distance to the Mandelbrot set in pixels (For Julia fractals this works momentarily only in the finite area)
    float dist2;       // The distance to the next iteration level in pixels
    vec2 value;        // The (complex) value of the last iteration (where its absolute value is <2; or the derivative of a point in the limit cycle if the iteration is infinite)
    int iter;          // The iteration number (a negative value means limit cycle of the corresponding length)
    float smoothiter;  // The iteration number smoothed out
    vec2 derivative;   // The (normalized) derivative of the last iteration
    vec2 coord;        // The coordinate (in the complex plane) of the current fragment
    vec2 screencoord;  // The screencoordinate of the current fragment
    float pixelsize;   // The size in pixels of the current fragment
} Data;

uniform sampler2D tex_aux; // The auxiliary texture if any has been chosen

The values “dist”, “dist2”, and “smoothiter” are actually functions of “iter”, “value”, and “derivative” but have been added to keep the necessary memory access from the GPU low.