// Includes all post-process common data (textures & sampler)
#include "PPCommonData.fxh"


//---------------------------------------------------------------------
// The filter data

float Luminance = 0.06f;
static const float fMiddleGray = 0.18f;
static const float fWhiteCutoff = 0.8f;


//-----------------------------------------------------------------------------
// Pixel Shader: BrightPassFilter
// Desc: Perform a high-pass filter on the source texture
//-----------------------------------------------------------------------------
float4 BrightPassFilter(float2 Tex : TEXCOORD0) : COLOR0
{
    float3 ColorOut = tex2D( g_samSrcColor, Tex );

    ColorOut *= fMiddleGray / (Luminance + 0.001f);
    ColorOut *= (1.0f + ( ColorOut/(fWhiteCutoff * fWhiteCutoff) ));
    ColorOut -= 5.0f;

    ColorOut = max(ColorOut, 0.0f);

    ColorOut /= (10.0f + ColorOut);

    return float4(ColorOut, 1.0f);
}


//-----------------------------------------------------------------------------
// Technique: PostProcess
// Desc: Performs post-processing effect that converts a colored image to
//       black and white.
//-----------------------------------------------------------------------------
technique PostProcess
<
	string Parameter0 = "Luminance";
	string Parameter0Desc = "(float)";
	int Parameter0Size = 1;
	float Parameter0Def = 0.06f;		
>
{
    pass p0
    {
		ZEnable = false;
		
        VertexShader = null;
        PixelShader = compile ps_2_0 BrightPassFilter();
    }
}
