-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburningShip.frag
58 lines (47 loc) · 1.46 KB
/
burningShip.frag
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
uniform vec2 resolution;
uniform float zoom;
uniform vec2 zoomCenter;
float interp(float x, float a, float b, float c, float d) {
return ((a + x) * d + (b - x) * c) / (a + b);
}
vec3 colormap(float t) {
vec3 colors[5];
colors[0] = vec3(0.07059, 0, 0.58039);
colors[1] = vec3(0.00784, 0.51765, 0.76078);
colors[2] = vec3(0.97647, 0.98431, 0.98824);
colors[3] = vec3(0.23922, 0, 0.50588);
colors[4] = vec3(0.41569, 0.20784, 0.61569);
float histogram[5];
histogram[0] = 0.0;
histogram[1] = 0.2;
histogram[2] = 0.4;
histogram[3] = 0.6;
histogram[4] = 1.0;
for (int i = 0; i < 4; i++) {
if (t >= histogram[i] && t <= histogram[i+1]) {
float factor = (t - histogram[i]) / (histogram[i+1] - histogram[i]);
return mix(colors[i], colors[i+1], factor);
}
}
return colors[0];
}
void main() {
//vec2 uv = (gl_FragCoord.xy / resolution) / zoom + zoomCenter;
vec2 uv = (gl_FragCoord.xy / zoom - resolution)/ resolution.y +zoomCenter;
vec3 col = vec3(0);
float zx = uv.x;
float zy = -uv.y;
int iter = 0;
int max_iter = 100;
while (zx * zx + zy * zy < 4.0 && iter < max_iter) {
float xtemp = zx * zx - zy * zy + uv.x;
zy = 2.0 * abs(zx * zy) - uv.y;
zx = xtemp;
iter += 1;
}
if (iter != max_iter) {
float t = log(float(iter)) / log(float(max_iter));
col = colormap(t);
}
gl_FragColor = vec4(col, 1.0);
}