/*=============================================================================
	DOFAndBloomBlendPixelShader.usf: Pixel shader for blending the blurred depth of field and bloom colors with the scene color.
	Copyright © 2006 Epic Games, Inc. All Rights Reserved.
=============================================================================*/

#include "Common.usf"
#include "DepthOfFieldCommon.usf"

sampler2D BlurredImage;

void Main(
	in float2 UV : TEXCOORD0,
	in float2 SceneUV : TEXCOORD1,
	out float4 OutColor : COLOR0
	)
{
	float SceneDepth = CalcSceneDepth(SceneUV);

	half3 FocusedSceneColor = CalcSceneColor(SceneUV);
	half FocusedWeight = saturate(1 - CalcUnfocusedPercent(SceneDepth));

	half3 UnfocusedSceneColor = tex2D(BlurredImage,UV).rgb;
	half UnfocusedWeight = tex2D(BlurredImage,UV).a;

	half WeightSum = max(FocusedWeight + UnfocusedWeight,0.001);

	//nse vbunny--
	#if SUPPORTS_FP_FILTERING
		OutColor = RETURN_COLOR( float4((FocusedSceneColor * FocusedWeight + UnfocusedSceneColor) / WeightSum, SceneDepth ) );
	#else
		OutColor = RETURN_COLOR( float4((FocusedSceneColor * FocusedWeight + UnfocusedSceneColor * 4) / WeightSum, SceneDepth ) );
	#endif
	//--nse vbunny
	
}
