uniform float ptimer;
uniform sampler2D ptex;
uniform sampler1D ctex;
uniform sampler1D stex;

void main()
{
	float t = ptimer * 0.0005;

	vec2 tc = gl_TexCoord[0].st;
	vec4 rc = texture2D(ptex, tc);

	float r = 1.0 - rc.r;
	float a = ((rc.b * 256.0 + rc.g) / 256.0) * 4.98;

	float r0 = texture1D(stex, 2.0 * r + t).r;
	float a0 = texture1D(stex, a + r0).r;

	float c = a0;

	vec4 color = texture1D(ctex, c);

	color.r = color.r * r;
	color.g = color.g * r * r;
	color.b = color.b * r * r * r;

	gl_FragColor = color;
}
