#version 330 core

// To be used with fsquad vertex shader!
in FSQuadOutput
{
	vec2 p; //position [-1,1]
	vec2 t; //tex coords [0,1]
} inData;

out vec4 fragColor;

//current intermediate buffer
uniform sampler2D texIntermediate;
uniform sampler2D texEye;


//mergeing the eye/intermediate buffers
void main(void)
{
	vec4 iVal = texture(texIntermediate,inData.t);
	vec4 eVal = texture(texEye,inData.t);

	//normalize eVal colors
	if(eVal.a > 0.0)
		eVal.rgb /= eVal.a;

	//eye buffer is transparent!
	fragColor = vec4(eVal.rgb*eVal.a + iVal.rgb*(1-eVal.a),eVal.a + iVal.a*(1-eVal.a));
	//fragColor = vec4(eVal.rgb + iVal.rgb,1.0);
	//fragColor = eVal;
}