uniform float ptimer;

const int iters = 256;

const float origin_z = -64.0;
const float plane_z = 0.0;
const float far_z = 64.0;

const float step = (far_z - origin_z) / float(iters);
const float scale = abs(plane_z - origin_z);

const float radius_bound = 24.0;
const float disp = 0.01;

float time;


float calc_this(vec3 p)
{
	float c = sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
	return c;
}

void main()
{
	time = ptimer * 0.0005;

	float xt = (gl_TexCoord[0].x - 0.5) * scale;
	float yt = (gl_TexCoord[0].y - 0.5) * scale;

	vec3 pos = vec3(xt, yt, plane_z);
	vec3 origin = vec3(0.0, 0.0, origin_z);

	vec3 dir = pos - origin;
	vec3 dirstep = normalize(dir) * step;

	pos = origin;

	float c;

	int i;
	for (i=0; i<iters; i++)
	{
		c = calc_this(pos);

		if (c < radius_bound)
		{
			break;
		}

		pos = pos + dirstep;
	}

	float cc = -pos.z / 24.0;
	if (i==iters)
		cc = 0.0;

	gl_FragColor = vec4(cc, cc, cc, cc);
}
