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


//---------------------------------------------------------------------
// Filter data

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


//-----------------------------------------------------------------------------
// Pixel Shader: ColorToneMap
// Desc: Perform a tone map filter on the source texture
//-----------------------------------------------------------------------------
float4 ColorToneMap(float2 Tex : TEXCOORD) : COLOR0
{
    float4 Color;

    Color = tex2D(g_samSrcColor, Tex) * fMiddleGray / ( Luminance + 0.001f );
    Color *= ( 1.0f + ( Color / ( fWhiteCutoff * fWhiteCutoff ) ) );
    Color /= ( 1.0f + Color );

    return Color;
}


//-----------------------------------------------------------------------------
// Technique: PostProcess
// Desc: Performs a tone mapping post-processing effect
//-----------------------------------------------------------------------------
technique PostProcess
<
    string Parameter0 = "Luminance";
    string Parameter0Desc = "(float)";
    int Parameter0Size = 1;
    float Parameter0Def = 0.08f;
>
{
    pass p0
    {
		ZEnable = false;
		
        VertexShader = null;
        PixelShader = compile ps_2_0 ColorToneMap();
    }
}
