#version 330

in vec2 UV;

layout(location = 0) out vec4 ND;
layout(location = 1) out vec4 albedo;

uniform sampler2D texNormalDepthPrev;
uniform sampler2D texNormalDepthNow;

uniform sampler2D texAlbedoPrev;
uniform sampler2D texAlbedoNow;
uniform vec2 resolution;


 
void main(){
	ND = texture(texNormalDepthNow, UV).rgba;
	albedo = texture(texAlbedoNow, UV).rgba;
	vec4 ND2 = texture(texNormalDepthPrev, UV).rgba; 
	vec4 albedo2 = texture(texAlbedoPrev, UV).rgba;

	if (ND.a<=0.001) {
		ND = ND2;
		albedo = albedo2;

		//ND.a = textureGather(texNormalDepthPrev, UV, 3).x;
	}
	
	if (!isnan(ND.b + albedo.a)) {
		ND.b = (ND.b + ND2.b)/2;
		albedo.a = (albedo.a + albedo2.a)/2;
	}

	if (isnan(ND.r + ND.g + ND.b + ND.a)) {
		//ND = vec4(0);
		//albedo = vec4(0);
		ND.a = 0;
	}
}