-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonopoke.frag
104 lines (87 loc) · 2.35 KB
/
monopoke.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
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
#version 400
in vec2 rad_pos;
out vec4 frag_colour;
vec3 HUEtoRGB(float H){
float R = abs(H * 6. - 3.) - 1.;
float G = 2 - abs(H * 6. - 2.);
float B = 2 - abs(H * 6. - 4.);
return clamp(vec3(R,G,B),0.0,1.0);
}
vec3 HSLtoRGB(vec3 HSL){
vec3 RGB = HUEtoRGB(HSL.x);
float C = (1. - abs(2. * HSL.z - 1.)) * HSL.y;
return (RGB - 0.5) * C + HSL.z;
}
float conform(float x){
return 0.5 + tanh(x) / 2.;
}
vec4 HyperbolicGreyScale(float x){
float y = conform(x);
return vec4(y,y,y,1.0);
}
uniform int num_pokes;
uniform float ct;
uniform float radius;
uniform float screenWidth;
uniform float screenHeight;
const float PI = 3.1415926535897932384626433832795;
void main () {
float x_offset = (screenWidth - screenHeight) / (2.0 * screenHeight);
float x = (gl_FragCoord.x / screenHeight) - x_offset;
float b = abs((gl_FragCoord.y - (screenHeight / 2)) / screenHeight);
float y = abs(((gl_FragCoord.y - (screenHeight / 2)) / screenHeight) - rad_pos.y);
float a = radius;
float ct0 = x;
float ct1 = sqrt((a - y)*(a - y) + x*x);
float ct2 = sqrt((a + y)*(a + y) + x*x);
float val = 0.0;
//int N = num_pokes;
int N = 1;
if (y < a){
if ((ct < ct0) || (ct > ct2)){
val = 0.0;
} else if ( (ct0 <= ct) && (ct <= ct1) ) {
val = 1.0;
} else {
val = acos( (ct*ct - x*x + y*y - a*a) / (2.0*y*sqrt(ct*ct - x*x))) / PI;
}
} else if (y > a) {
if ((ct <= ct1) || (ct > ct2)){
val = 0.0;
} else {
val = acos( (ct*ct - x*x + y*y - a*a) / (2.0*y*sqrt(ct*ct - x*x))) / PI;
}
} else {
if ((ct < ct0) || (ct > ct2)){
val = 0.0;
} else if ( (ct1 < ct) && (ct <= ct2) ) {
val = acos( (ct*ct - x*x) / (2.0*a)) / PI;
} else {
val = 0.5;
}
}
//frag_colour = HyperbolicGreyScale(val);
/*
float v = val / N;
if ((b > 0.495) || (x > 0.995)) {
frag_colour = vec4(1.0,1.0,1.0,1.0);
} else if (x < 0.005) {
frag_colour = vec4(1.0,1.0,1.0,1.0);
} else if (x < 0.01) {
if (y < a) {
frag_colour = vec4(1.0,1.0,0.0,1.0);
} else {
frag_colour = vec4(1.0,0.0,0.0,0.0);
}
} else {
if (v > 1.0){
frag_colour = vec4(1.0,0.0,0.0,1.0);
} else if (v < 0.0){
frag_colour = vec4(0.0,0.0,1.0,1.0);
} else {
frag_colour = vec4(v,v,v,1.0);
}
}
*/
frag_colour = vec4(gl_FragCoord.x, gl_FragCoord.y,0.0,1.0);
}