summaryrefslogtreecommitdiff
path: root/shader.frag
blob: 9d8d7fa61f283fafdd518dcdc6f309ab35d1eb9d (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#version 450 core
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 resolution;
uniform float time;
uniform float ticks;
uniform int program;

uniform sampler2D images[8];
layout (binding = 0,rgba32f) uniform image2D backbuffer;
uniform float params[4];

out vec4 fragColor;

float random (in float x) {
  return fract(sin(x)*43758.5453123)-0.5;
}

vec2 st() {
	return gl_FragCoord.xy/resolution.xy;
}
ivec2 ist() {
	return ivec2(gl_FragCoord.xy/resolution.xy*resolution);
}

vec2 zoom(vec2 st, float amount) {
  st -= 0.5;
  st *= amount;
  st += 0.5;
  return st;
}

vec2 translate(vec2 st, vec2 amount) {
  st -= 0.5;
  st += amount;
  st += 0.5;
  return st;
}

vec2 rotate(vec2 st, float angle) {
  st -= 0.5;
  st *= angle;
  st += 0.5;
  return st;
}

mat2 rotate2d(float _angle){
  return mat2(cos(_angle),-sin(_angle), sin(_angle),cos(_angle));
}

void main (void) {
  vec4 img; 
  vec2 coord;
  if (program == 0) {
    coord = zoom(st(),1.0-0.5*(1.0-params[0]));
    img = texture2D(images[0],coord);
    vec2 tc = st();
    tc = zoom(tc,2.0);
    tc.y *= 1.5;
    tc = translate(tc,vec2(-0.35,0.55));
    vec4 title = texture2D(images[1],tc);
    img -= params[1]*0.7*title;
  }
  else if (program == 1) {
    coord = zoom(st(),1.0-0.5*(1.0-params[0]));
    img = texture2D(images[0],coord);
    coord = zoom(st(),1.0-0.5*(1.0-params[2]));
    coord = translate(coord,vec2(-0.1,-0.1));
    vec3 i2 = texture2D(images[2],coord).rgb;
    img.rgb = 2.5*pow((1.0-2.3*img.rgb),1.0+(1.0-params[1])*2*i2);
  }
  else if (program == 2) {
    coord = zoom(st(),1.0-0.5*(1.0-params[2]));
    coord = translate(coord,vec2(-0.1,-0.1));
    img = texture2D(images[2],coord);
    coord = zoom(st(),1.0-0.5*(1.0-params[0]));
    vec3 i2 = texture2D(images[0],coord).rgb;
    img.rgb = pow((1.0-2.3*img.rgb),1.0+(1.0-params[1])*2*i2);
  }
  else if (program == 3) {
    coord = zoom(st(),1.0-0.5*(1.0-params[0]));
    coord = rotate(coord,0.1);
    img = texture2D(images[3],coord);
    coord = zoom(st(),0.7-0.5*(1.0-params[2]));
    coord = translate(coord,vec2(-0.1,0.2));
    vec3 i2 = texture2D(images[2],coord).rgb;
    img.rgb = pow((1.0-2.3*img.rgb),params[3]*5*i2);
    /*
    coord = st() + 0.5;
    coord -= 0.5;
    img = texture2D(images[3],coord);
    coord = zoom(st(),0.5*(1.0-0.5*params[0]));
    coord = rotate2d(sin(ticks))*coord;
    vec3 i2 = texture2D(images[0],coord).rgb;
    img.rgb = 2.0*pow((1.0-2.0*i2),params[3]*50*img.rgb);
    */
  }
  else if (program == 4) {
    coord = zoom(st(),(1.0-1.5*params[0]));
    img = texture2D(images[3],coord);
    coord = zoom(st(),0.5*(1.0-0.5*params[2]));
    coord = translate(coord,vec2(0.2,0.15));
    coord = rotate(coord,-0.1);
    vec3 i2 = texture2D(images[2],coord).rgb;
    img.rgb = pow((1.0-2.3*img.rgb),params[3]*5*i2);
  }
  else if (program == 5) {
    coord = zoom(st(),(1.0-1.5*params[0]));
    img = texture2D(images[2],coord);
    coord = zoom(st(),0.5*(1.0-0.5*params[2]));
    coord = translate(coord,vec2(0.2,0.15));
    vec3 i2 = texture2D(images[3],coord).rgb;
    img.rgb = pow(img.rgb,5*i2);
  }
  else if (program == 6) {
    coord = zoom(st(),(1.0-1.5*params[0]));
    img = texture2D(images[2],coord);
    coord = zoom(st(),0.5*(1.0-0.5*params[2]));
    coord = translate(coord,vec2(0.2,0.15));
    vec3 i2 = texture2D(images[3],coord).rgb;
    img.rgb = pow(img.rgb,5*i2);
    vec2 tc = st();
    tc = zoom(tc,2.0);
    tc.y *= 1.5;
    tc = translate(tc,vec2(-0.35,0.15));
    vec4 title = texture2D(images[1],tc);
    tc = st();
    tc = zoom(tc,2.0);
    tc = translate(tc,vec2(-0.35,0.35));
    tc.y *= 3.5;
    vec4 subtitle = texture2D(images[4],tc);
    img += params[3]*title + subtitle;
  }
  imageStore(backbuffer,ist(),img);
  if (program != 0) {
    vec4 feedback = imageLoad(backbuffer,ist());
    img = mix(feedback,img,0.4);
  }
  fragColor = img;
  /*
  fragColor = vec4(params[1]);
    feedback.b += 0.01*cos(time/4.);
    color.r = max(i.r,feedback.r);
  */
}