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

struct FragOut
{
	float4 col : COLOR;
};

FragOut main(VertOut vin,
	uniform sampler2D tex0 : TEXUNIT0
      )
{
	//float texel_height=800.0f;
	//float texel_width=600.0f;
	float texel_height=1.0;
	float texel_width=1.0;
	float step_height=1.0/800.0;
	float step_width=1.0/600.0;
   
	FragOut fout;

  float4 tcol=tex2D(tex0,vin.tex0);
  if(tcol.g>0.8)
  {
    // Blur
    //tcol.g=0;
	fout.col = 0;
	fout.col += tex2D(tex0, vin.tex0 + float2(-1 * step_width, -1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
	fout.col += tex2D(tex0, vin.tex0 + float2(0, 0) * float2(texel_width, texel_width)) * 0.5f;
	fout.col += tex2D(tex0, vin.tex0 + float2(1 * step_width, 1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
    fout.col=float4(0,1,0,1);
  } else
  {
    float4 grey = dot(float3(0.222, 0.707, 0.071), tcol);
//    fout.col=tcol;
    fout.col=grey;
  }
  return fout;

/*
	fout.col = 0;

//    for (int i= 1; i < 6; i++)
//		if (vert)
  //       c += tex2D(tex0, vin.tex0 + float2(0, i-3) * texel_size) * weight[i]
	//	else
      //     c += tex2D(tex0, vin.tex0 + float2(i-3, 0) * texel_size) * weight[i];
//	fout.col += tex2D(tex0, vin.tex0 + float2(-4 * step_width, -4 * step_height) * float2(texel_width, texel_width)) * 0.1f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(-3 * step_width, -3 * step_height) * float2(texel_width, texel_width)) * 0.1f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(-2 * step_width, -2 * step_height) * float2(texel_width, texel_width)) * 0.15f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-1 * step_width, -1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
	fout.col += tex2D(tex0, vin.tex0 + float2(0, 0) * float2(texel_width, texel_width)) * 0.5f;
	fout.col += tex2D(tex0, vin.tex0 + float2(1 * step_width, 1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(2* step_width, 2 *step_height) * float2(texel_width, texel_width)) * 0.15f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(3 * step_width, 3 * step_height) * float2(texel_width, texel_width)) * 0.1f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(4 * step_width, 4 * step_height) * float2(texel_width, texel_width)) * 0.1f;

//	fout.col = float4(avg1 + avg2);
    
    //fout.col = 1.0-tex2D(tex0, vin.tex0);
    //fout.col = 1.8*tex2D(tex0, vin.tex0);
    //fout.col = tex2D(tex0, vin.tex0)*tex2D(tex0, vin.tex0)*1.5;
	return fout;
*/

}


/*
struct VertOut
{
	float4 pos : POSITION;
	float4 col : COLOR0;
	float2 tex0 : TEXCOORD0;
};

struct FragOut
{
	float4 col : COLOR;
};

FragOut main(VertOut vin,
	uniform sampler2D tex0 : TEXUNIT0
      )
{
	//float texel_height=800.0f;
	//float texel_width=600.0f;
	float texel_height=2.0;
	float texel_width=2.0;
	float step_height=1.0/800.0;
	float step_width=1.0/600.0;
   
	FragOut fout;

	fout.col = 0;

//    for (int i= 1; i < 6; i++)
//		if (vert)
  //       c += tex2D(tex0, vin.tex0 + float2(0, i-3) * texel_size) * weight[i]
	//	else
      //     c += tex2D(tex0, vin.tex0 + float2(i-3, 0) * texel_size) * weight[i];
//	fout.col += tex2D(tex0, vin.tex0 + float2(-4 * step_width, -4 * step_height) * float2(texel_width, texel_width)) * 0.1f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(-3 * step_width, -3 * step_height) * float2(texel_width, texel_width)) * 0.1f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(-2 * step_width, -2 * step_height) * float2(texel_width, texel_width)) * 0.15f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-1 * step_width, -1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
	fout.col += tex2D(tex0, vin.tex0 + float2(0, 0) * float2(texel_width, texel_width)) * 0.5f;
	fout.col += tex2D(tex0, vin.tex0 + float2(1 * step_width, 1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(2* step_width, 2 *step_height) * float2(texel_width, texel_width)) * 0.15f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(3 * step_width, 3 * step_height) * float2(texel_width, texel_width)) * 0.1f;
//	fout.col += tex2D(tex0, vin.tex0 + float2(4 * step_width, 4 * step_height) * float2(texel_width, texel_width)) * 0.1f;

//	fout.col = float4(avg1 + avg2);
    
    //fout.col = 1.0-tex2D(tex0, vin.tex0);
    //fout.col = 1.8*tex2D(tex0, vin.tex0);
    //fout.col = tex2D(tex0, vin.tex0)*tex2D(tex0, vin.tex0)*1.5;
	return fout;
}
*/


/*
// Gamma
struct VertOut
{
	float4 pos : POSITION;
	float4 col : COLOR0;
	float2 tex0 : TEXCOORD0;
};

struct FragOut
{
	float4 col : COLOR;
};

FragOut main(VertOut vin,
	uniform sampler2D texNormal : TEXUNIT0,
	uniform float minGamma = 0.5,
	uniform float avgGamma = 0.5,
	uniform float maxGamma = 1.0)
{
	FragOut fout;
    

	float4 colNormal1 = tex2D(texNormal, vin.tex0);
	float lum = 0.299*colNormal1.r + 0.587*colNormal1.g + 0.114*colNormal1.b;
    
	if (minGamma > 5.0)
	{
		colNormal1.r = lum;
		colNormal1.g = lum;
		colNormal1.b = lum;
	}
	if (minGamma <= 1.0)
	{
		const float BiasMax = 0.5f;
		float Diff = ( avgGamma - minGamma ) / (maxGamma - minGamma);
		float Bias = 1.0f + Diff * BiasMax;
		float gam = pow( (lum - minGamma) / (maxGamma - minGamma), Bias);
		if (lum < minGamma)
		{
	  		colNormal1.r = colNormal1.r-lum;
			colNormal1.g = colNormal1.g-lum;
			colNormal1.b = colNormal1.b-lum;
			}
		else if (lum > maxGamma)
		{
	  		colNormal1.r = colNormal1.r/lum;
			colNormal1.g = colNormal1.g/lum;
			colNormal1.b = colNormal1.b/lum;
			}
		else 
		{
	  		colNormal1.r = colNormal1.r*gam/lum;
			colNormal1.g = colNormal1.g*gam/lum;
			colNormal1.b = colNormal1.b*gam/lum;
		} 
	}

    fout.col = colNormal1;
    return fout;
}
*/


/*
struct Output
{
  float4 color : COLOR;
};

Output main(float2 texCoord : TEXCOORD0,
            uniform sampler2D decal)
{
  Output OUT;
  //OUT.color=color;
  OUT.color=tex2D(decal,texCoord);
  return OUT;
}
*/
