1#version 100
2
3// Copyright Alastair F. Donaldson and Hugues Evrard, Imperial College London, 2017
4
5#ifdef GL_ES
6#ifdef GL_FRAGMENT_PRECISION_HIGH
7precision highp float;
8precision highp int;
9#else
10precision mediump float;
11precision mediump int;
12#endif
13#endif
14
15uniform vec2 injectionSwitch;
16
17uniform vec2 resolution;
18
19bool checkSwap(float a, float b)
20{
21    return gl_FragCoord.y < resolution.y / 2.0 ? a > b : a < b;
22}
23void main()
24{
25    float data[10];
26    for(
27        int i = 0;
28        i < 10;
29        i ++
30    )
31        {
32            data[i] = float(10 - i) * injectionSwitch.y;
33        }
34    for(
35        int i = 0;
36        i < 9;
37        i ++
38    )
39        {
40            for(
41                int j = 0;
42                j < 10;
43                j ++
44            )
45                {
46                    if(j < i + 1)
47                        {
48                            continue;
49                        }
50                    bool doSwap = checkSwap(data[i], data[j]);
51                    if(doSwap)
52                        {
53                            float temp = data[i];
54                            data[i] = data[j];
55                            data[j] = temp;
56                        }
57                }
58        }
59    if(gl_FragCoord.x < resolution.x / 2.0)
60        {
61            gl_FragColor = vec4(data[0] / 10.0, data[5] / 10.0, data[9] / 10.0, 1.0);
62        }
63    else
64        {
65            gl_FragColor = vec4(data[5] / 10.0, data[9] / 10.0, data[0] / 10.0, 1.0);
66        }
67}
68