attribute vec3 position;
uniform mat4 modelmat;
uniform mat4 pmat;
uniform mediump float t;

varying mediump vec3 vpos;
varying mediump float depth;

void main() {
	mediump float c, s, theta, w;

	theta = (.75 + .25 * sin(t / 10000.)) * cos(t / 1000.);
	c = cos(position.y * theta);
	s = sin(position.y * theta);
	w = 1.25 - .25 * sin(t / 5000.);

	vec4 rcoords = modelmat * vec4(
		w*(position.x * c + position.z * s),
		w*position.y,
		w*(-position.x * s + position.z * c),
		1.0
	);
	gl_Position = pmat * rcoords;
	gl_PointSize = w * 2.0 * length(position);
	depth = rcoords.z + 5.0 - 1.73205;
	vpos = position;
}
varying mediump vec3 vpos;
varying mediump float depth;

void main() {
	gl_FragColor = vec4(
		(1.0 + vpos.x) / 2.0,
		(1.0 + vpos.y) / 2.0,
		(1.0 + vpos.z) / 2.0,
		exp(-1.0 * depth * depth)
	);
}