
layout (location = 0) out vec4 C;

in vec3 out_pos;
//in float point_sz;
in vec4 color;

in float radial_uv;
in float dof_amt;


float Bayer2(vec2 a) {
	a = floor(a);
	return fract(a.x / 2. + a.y * a.y * .75);
}

#define Bayer4(a)   (Bayer2 (.5 *(a)) * .25 + Bayer2(a))
#define Bayer8(a)   (Bayer4 (.5 *(a)) * .25 + Bayer2(a))
#define Bayer16(a)  (Bayer8 (.5 *(a)) * .25 + Bayer2(a))
#define Bayer32(a)  (Bayer16(.5 *(a)) * .25 + Bayer2(a))
#define Bayer64(a)  (Bayer32(.5 *(a)) * .25 + Bayer2(a))


void main(){
//	vec4 cc = color;
//	vec2 uv = gl_PointCoord;
//	uv -= 0.5;
//	if(length(uv) > 0.45){
//		discard;
//	}
	C = color;

	bool dof = false;
	
	if(dof){
		float sd_circ = radial_uv;
		//	C.a = clamp(1.-sd_circ,0.,1.0);
		//	
		C.a = C.a * pow(
		(1.-sd_circ + clamp(1 - dof_amt*dof_amt*0.005, 0., 1.0)),
		1.
		);
		C.a += (Bayer8(U.xy) - 0.5)*2.0;
		//	C.a = mix(
		//		C.a,
		//		C.a*pow((1.-sd_circ),2.),
		//		clamp(dof_amt*dof_amt,0.,1.)
		//	);
		//	C.a = mix(C.a,C.a*pow((sd_circ),0.1),clamp(dof_amt*dof_amt,0.,1.));
		//	C.a = C.a*pow(max((1.-sd_circ),0.),2.);
		C.a *= 1.0/(1+dof_amt*dof_amt*0.005);
		C.a = clamp(C.a, 0., 1.0);
		//	C.a *= 1.0;
		
	}
//	C = vec4(color.rgb,alpha);
}
