// Blur vertical and mix with tex1 (which contains original drawing)

struct VertOut
{
	float4 pos : POSITION;
	float4 col : COLOR0;
	float2 tc0 : TEXCOORD0;
};

struct FragOut
{
	float4 col : COLOR;
};

FragOut main(VertOut vin,
	uniform sampler2D tex0   : TEXUNIT0,
	uniform sampler2D texOrg : TEXUNIT1
      )
{
  FragOut fOut;

  float2 BlurOffset1    = float2( 0.00125,0 );
  float2 BlurOffset2    = float2( 0,0.0016667 );

  //float2 BlurOffset1    = float2( 0.0125,0 );
  //float2 BlurOffset2    = float2( 0,0.016667 );

  float PixelWeight[8] = { 0.2537, 0.2185, 0.0821, 0.0461, 0.0262, 0.0162, 0.0102, 0.0052 };
  float scaleTex=0.75;
  float stretchX=1.0;
  float stretchY=1.0;

  //float4 colorT = tex2D(tex0,vin.tc0);

  float4 color=0;

  for( int j = 0; j < 8; ++j )
  {
    color += tex2D(tex0, vin.tc0 + ( BlurOffset2 * j *stretchY) ) * PixelWeight[j]*scaleTex;
    color += tex2D(tex0, vin.tc0 - ( BlurOffset2 * j *stretchY) ) * PixelWeight[j]*scaleTex;
  }

  // Mix with original
  float4 colorT=tex2D(texOrg,vin.tc0);

  float4 baseCol=color*1.0+colorT*0.0;

  // Expose for HDR-like exposure control
  //float exposure=-0.8;
  //baseCol=1.0-exp(baseCol*exposure);

  // Overlay mode (Photoshop)
  float4 cColor=baseCol;
  if(cColor.r<0.5)cColor.r*=2.0*cColor.r;
  else            cColor.r=4*cColor.r-2*cColor.r*cColor.r-1;
  if(cColor.g<0.5)cColor.g*=2.0*cColor.g;
  else            cColor.g=4*cColor.g-2*cColor.g*cColor.g-1;
  if(cColor.b<0.5)cColor.b*=2.0*cColor.b;
  else            cColor.b=4*cColor.b-2*cColor.b*cColor.b-1;
  // Ambient
  //cColor+=0.1;
  
  //fOut.col=baseCol;
  fOut.col=cColor;

  return fOut;
} 


