//
// HDR+bloom+vignette
// Post-processing filter.
// RvG, 21-4-09
//

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

struct VertOut
{
  float2 tc0 : TEXCOORD0;
  float4 col : COLOR;
};

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=tex2D(sceneMap,vin.tc0); 

  // Bloom additive
  float4 color,bloomColor;
  bloomColor=BloomCombineMaps3(bloomMap1,bloomMap2,bloomMap3,vin.tc0);
  color=BloomMix(sceneColor,bloomColor);

  // Vignette
  color*=Vignette(vin.tc0);

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

  // Blending (optional) for motion blur through half-painting
  color.a=vin.col.a;

  // Output final color
  fout.col=color;

  return fout;
} 
