//
// HDR+bloom2+motion blur
// Post-processing filter.
// RvG, 21-4-09
//

#include "../common/hdr.cg"
#include "../common/colors.cg"
#include "bloom.cg"
#include "motion_blur.cg"
#include "common_fs.cg"

struct VertOut
{
	float2 tc0 : TEXCOORD0;
};

struct FragOut
{
	float4 col : COLOR;
};

FragOut main(
  VertOut vin,
	uniform sampler2D sceneMap    : TEXUNIT0,
	uniform sampler2D velocityMap : TEXUNIT1,
  // Multiple bloom levels (512x512, 256x256, 128x128)
	uniform sampler2D bloomMap1   : TEXUNIT2,
	uniform sampler2D bloomMap2   : TEXUNIT3,
	uniform sampler2D bloomMap3   : TEXUNIT4,
  uniform float exposure
)
{
  FragOut fout;

  // Scene texel
  float4 sceneColor=MotionBlur2(sceneMap,velocityMap,vin.tc0,1024.0,768.0);
  
  // Bloom additive
  float4 color,bloomColor;
  bloomColor=BloomCombineMaps3(bloomMap1,bloomMap2,bloomMap3,vin.tc0);
  color=BloomMix(sceneColor,bloomColor);

  // Vignette
  float2 texCoord=vin.tc0-0.5;
	float vignette=1.0-dot(texCoord,texCoord);
	vignette*=vignette;
	color*=vignette;
  
//color=bloomColor;
//color=sceneColor;

  //const float exposure=1.0;
  color=ToneMapHDR(color,exposure);
  
  // Color op - strengthen contrast
  //color=ColorOverlayHalf(color);

//color=bloomColor;

  // Output final color
  fout.col=color;
//fout.col=bloomColor;

  return fout;
} 
