//-----------------------------------------------------------------------------
// File: PP_ColorBrightPass.fx
//
// Desc: Effect file for image post-processing sample.  This effect contains
//       a single technique with a pixel shader that performs a bright pass
//       on the input texture.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------




texture tex0;

sampler2D g_samSrcColor =
sampler_state
{
    Texture = <tex0>;
    AddressU = Clamp;
    AddressV = Clamp;
    MinFilter = Point;
    MagFilter = Linear;
    MipFilter = Linear;
};

float Luminance = 0.022f;
static const float fMiddleGray = 0.12f;
static const float fWhiteCutoff = 0.8f;
float3 LuminanceConv = { 0.2125f, 0.7154f, 0.0721f };

//-----------------------------------------------------------------------------
// Pixel Shader: BrightPassFilter
// Desc: Perform a high-pass filter on the source texture
//-----------------------------------------------------------------------------



float4 Contrast( in 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 );
   
}



float4 Grayscale( float2 Tex : TEXCOORD0 ) : COLOR0
{
    return dot( (float3)tex2D( g_samSrcColor, Tex ), LuminanceConv );
}

//-----------------------------------------------------------------------------
// Technique: PostProcess
// Desc: Performs post-processing effect that converts a colored image to
//       black and white.
//-----------------------------------------------------------------------------
technique tec0
{
//    pass p0
//    {
//        VertexShader = null;
//        PixelShader = compile ps_2_0 Contrast();
//        ZEnable = false;
//    }
    pass p0
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 Grayscale();
        ZEnable = false;
    }
//    pass p1
//    {
//       VertexShader = null;
//        PixelShader = compile ps_2_0 HorzBloom();
//        ZEnable = false;
//    }

//    pass p2
//    {
//        VertexShader = null;
//        PixelShader = compile ps_2_0 VertBloom();
//        ZEnable = false;
//    }
//    pass p3
//    {
//        VertexShader = null;
//        PixelShader = compile ps_2_0 VertBloom();
//        ZEnable = false;
//    }

}
