const SPHERICAL_FRAGMENT_SHADER: &str = "
#version 330 core
layout(location=0) out vec4 color;
uniform sampler2D image;
in vec2 lon_lat;
void main() {
vec3 direction = vec3(
sin(lon_lat.x)*cos(lon_lat.y),
sin(lon_lat.y),
cos(lon_lat.x)*cos(lon_lat.y)
);
vec2 vTexCoord;
if ((direction.y > abs(direction.x)) && (direction.y > abs(direction.z))) {
// Looking up
vTexCoord.x = direction.z / (direction.y*6.0) + 5.0/6.0;
vTexCoord.y = direction.x / (direction.y*4.0) + 1.0/4.0;
} else if ((direction.y < -abs(direction.x)) && (direction.y < -abs(direction.z))) {
// Looking down
vTexCoord.x = direction.z / (direction.y*6.0) + 1.0/6.0;
vTexCoord.y = -direction.x / (direction.y*4.0) + 1.0/4.0;
} else if (direction.z < -abs(direction.x)) {
// Looking back
vTexCoord.x = -direction.y / (direction.z*6.0) + 3.0/6.0;
vTexCoord.y = -direction.x / (direction.z*4.0) + 1.0/4.0;
} else if (direction.x < -abs(direction.z)) {
// Looking left
vTexCoord.x = -direction.z / (direction.x*6.0) + 1.0/6.0;
vTexCoord.y = -direction.y / (direction.x*4.0) + 3.0/4.0;
} else if (direction.x > abs(direction.z)) {
// Looking right
vTexCoord.x = -direction.z / (direction.x*6.0) + 5.0/6.0;
vTexCoord.y = direction.y / (direction.x*4.0) + 3.0/4.0;
} else {
// Looking ahead
vTexCoord.x = direction.x / (direction.z*6.0) + 3.0/6.0;
vTexCoord.y = direction.y / (direction.z*4.0) + 3.0/4.0;
}
color = texture(image, vTexCoord);
}
";