_dofBlur.vsh
{
	include generic_vertex.vsh
}

_dofBlur.fsh
{
	uniform sampler2DRect	u_ScreenBuffer;
	uniform sampler2DRect	u_DepthBuffer;
	uniform vec2		u_dofParms;	// x = dofFocus, y = dofBias
	uniform vec3		u_depthParms;	// x = -zFar * zNear, y = zFar - zNear, z = zFar
	uniform vec4 		u_dofOffsets0;
	uniform vec4 		u_dofOffsets1;
	uniform vec4 		u_dofOffsets2;
	uniform vec4 		u_dofOffsets3;
	uniform vec4 		u_dofOffsets4;
	uniform vec4 		u_dofOffsets5;
	uniform vec4 		u_dofOffsets6;
	uniform vec4 		u_dofOffsets7;
	out	vec4	fragData;

	void main(void)
	{
		vec4 col;
		float expDepth = texture(u_DepthBuffer, gl_FragCoord.xy).r;
		float linDepth = u_depthParms.x / (expDepth * u_depthParms.y - u_depthParms.z);
		float factor = linDepth - abs(u_dofParms.x);
		float dofBlur = clamp(factor * u_dofParms.y, -5.0, 5.0);

		if (u_dofParms.x >= 0.0)
		{
			col = texture(u_ScreenBuffer, gl_FragCoord.xy);
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets0.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets0.zw * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets1.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets1.zw * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets2.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets2.zw * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets3.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets3.zw * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets4.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets4.zw * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets5.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets5.zw * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets6.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets6.zw * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets7.xy * dofBlur).rgb;
			col.rgb += texture(u_ScreenBuffer, gl_FragCoord.xy + u_dofOffsets7.zw * dofBlur).rgb;
			col.rgb *= (1.0 / 17.0);
		}
		else
		{
			dofBlur = abs(dofBlur / 5.0);
			col = vec4(dofBlur, dofBlur, dofBlur, 1.0);
		}
		fragData = col;
	}
}
