aboutsummaryrefslogtreecommitdiff
path: root/shader/fragment.glsl
blob: 67202361a82d44d5ac502ab78ac087c6ae032d2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#version 400 core

out vec4            out_color;

uniform int         u_width;
uniform int         u_height;

uniform float       u_real_start;
uniform float       u_real_end;
uniform float       u_imag_start;
uniform float       u_imag_end;

uniform int         u_iterations;

uniform sampler1D   u_texture;

#define ESCAPE_RADIUS 4.0

void main()
{
    float   ca = u_real_start + float(gl_FragCoord.x) / float(u_width) * (u_real_end - u_real_start);
    float   cb = u_imag_start + float(gl_FragCoord.y) / float(u_height) * (u_imag_end - u_imag_start);
    float	zr = ca;
    float	zi = cb;

    float	zr_square;
    float	zi_square;
    int     n;

    for (n = 0; n < u_iterations; n++)
    {
        zi_square = zi * zi;
        zr_square = zr * zr;
        if (zr_square + zi_square > ESCAPE_RADIUS)
            break;
        zi = 2.0 * zr * zi;
        zr = zr_square - zi_square;
        zi += cb;
        zr += ca;
    }

    if (n == u_iterations)
        out_color = vec4(0.0, 0.0, 0.0, 1.0);
    else
        out_color = texture1D(u_texture, float(n) / float(u_iterations));
}