-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplefragshader.glsl
52 lines (50 loc) · 1.77 KB
/
simplefragshader.glsl
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
varying vec2 tcoord;
uniform mat4 unif_matrix;
uniform sampler2D tex;
const float M_PI = 3.1415926535;
const float aspect = 640.0 / 480.0;
const vec2 center1 = vec2(0.50, 0.53);
const vec2 center2 = vec2(0.49, 0.50);
void main(void) {
float u = 0.0;
float v = 0.0;
vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);
float phi_orig = M_PI / 2.0 - M_PI * tcoord.y;
float theta_orig = 2.0 * M_PI * tcoord.x;
pos.x = cos(phi_orig) * cos(theta_orig);
pos.y = cos(phi_orig) * sin(theta_orig);
pos.z = sin(phi_orig);
pos = unif_matrix * pos;
float phi = asin(pos.z);
float theta = atan(pos.y, pos.x);
if(phi > -0.1 && phi < 0.1) {
} else if (phi > 0.0) {
float r = (phi - M_PI / 2.0) / M_PI;
float theta2 = -theta;
u = r * cos(theta2) + center1.x;
v = aspect * r * sin(theta2) + center1.y;
if (u <= 0.0 || u > 1.0 || v <= 0.0 || v > 1.0) {
u = 0.0;
v = 0.0;
} else {
u = u * 0.5;
}
} else {
float r = (phi + M_PI / 2.0) / M_PI;
float theta2 = theta - M_PI / 2.0 - M_PI / 45.0;
u = r * cos(theta2) + center2.x;
v = aspect * r * sin(theta2) + center2.y;
if (u <= 0.0 || u > 1.0 || v <= 0.0 || v > 1.0) {
u = 0.0;
v = 0.0;
} else {
u = u * 0.5 + 0.5;
}
}
if (u == 0.0 && v == 0.0) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
else {
gl_FragColor = texture2D(tex, vec2(u, v));
}
}