#version 150 core

uniform sampler2D in_texture;
uniform sampler2D in_depth_texture;
uniform sampler2D in_blurred_texture;
uniform float near_blur;
uniform float far_blur;

uniform float border; //border of postprocessing

in vec2 ex_texcoord;

out vec4 out_color;

void main(void) {
	vec4 texel = texture(in_texture, ex_texcoord);
	float depth = texture(in_depth_texture, ex_texcoord).r;
	vec4 blur_texel = texture(in_blurred_texture, ex_texcoord);

	//smooth transitions on near and far blur border
	//float far_factor = smoothstep(0.25, 0.35, depth);
	//float near_factor = 1 - smoothstep(0.05, 0.1, depth);
	float far_factor = smoothstep(far_blur, far_blur+0.15, depth);
	float near_factor = 1 - smoothstep(near_blur, near_blur + 0.05, depth);
	float blur_factor = depth > 0.2 ? far_factor : near_factor;
	out_color = mix(texel, blur_texel, blur_factor);
}