float a(float b, int d)
{
	float v = 0;
	int[] C = int[](
		-12,0,7,40,
		-12,0,7,12,
		-15,0,5,9,
		-4,-4,0,3,
		-5,-5,2,10,
		-7,0,5,12
		);
        int[] S = int[](0, 0, 0, 0,
			1, 1, 1, 1,
			2, 2, 0, 0,
			3, 4, 5, 5,

			1, 1, 1, 1,
			1, 1, 1, 1,
			5, 5, 0, 0,
			3, 4, 5, 5,
	  
			1, 1, 1, 1,
			1, 1, 1, 1
		);
	b *= b>400e4?cos((b-400e4)*12e-7):1;
	int s = int(b/13000);

	for (int i=1;i<20;i+=i) {
		v += mod((b * (.00318 * pow(1.0596,float((C[S[s / 8] * 4])))
				  + i * (1e-6 + d * 2e-8))), 1.0) * (s>127?.07 * cos(b/2758.7):.03);
		for (int k=1 ; k < (s>187 ? 6 : 5) ; k++) {
			int p = int[](
					7, 5, 7, 7, 40, 3, 2, -2,
					0, 3, 0, 0, 0, 0, 0, 40,

					7, 5, 7, 7, 40, 5, 7, 10,
					9, 5, 7, 7, 12, 7, 3, 0,

					5, 7, 9, 9, 9, 9, 7, 5,
					7, 0, 3, 3, 3, 3, 2, 0,

					3, 3, 3, 3, -2, -2, 2, -2,
					-5, -3, -3, -3, -3, -3, -3, 40
			  
					)
				[(s/2)%64] + 12;
			int n = k>3? p + (k>4?
					  3+(1064>>(p%12)&1) : 0) :
					  C[S[s / 8] * 4 + k];
			v += n<30?sin((b + k * 400) * .02 * pow(1.0596,float(n)) * i) * .08 / (i + 1 + sin(b * 9e-4 + i) * .3):0;
		}
	}
	return v;
}

uniform vec3 l[3];
void main()
{
	float v = 0;
	int p = int(gl_FragCoord.y * l[0].y + gl_FragCoord.x + l[0].x);
	for (int i=1;i<20;i+=3) {
		v += (p>880e4?cos((p-880e4)*42e-7):1)*a(p/2 - i * 11000, p%2) / i;
	}
	gl_FragColor=vec4(.5+v);
}
