varying vec2 v_texcoord;
uniform sampler2D u_texture;
void main()
{
float PI = 3.14159265358979323846264;
float HALF_PI = PI * 0.5;
float TWO_PI = PI * 2.0;
float SCALE = 0.45;
float PLANET_FACTOR = 4.7;
float cosphi0 = cos(PLANET_FACTOR);
float sinphi0 = sin(PLANET_FACTOR);
float x = (v_texcoord.x - 0.5) / SCALE;
float y = (0.5 - v_texcoord.y) / SCALE;
float rho = sqrt(x * x + y * y);
float c = 2.0 * atan(rho);
float sinc = sin(c);
float cosc = cos(c);
float lambda = atan(x * sinc, rho * cosc);
float phi = asin(y * sinc / rho);
float cosphi = cos(phi);
float x1 = cos(lambda) * cosphi;
float y1 = sin(lambda) * cosphi;
float z1 = sin(phi);
lambda = atan(y1, x1 * cosphi0 + z1 * sinphi0);
phi = asin(z1 * cosphi0 - x1 * sinphi0);
vec2 coord = vec2((lambda + PI) / TWO_PI, (phi + HALF_PI) / PI);
gl_FragColor = texture2D(u_texture, coord);
}