Code Snipped: Contrast Shader


This simple post effect shows how to change the constrast of an image.
We just recover the texture color and apply a simple approximated Contrast equation.

This approach is very simple and give good results

sampler baseSampler : register(s0);

float Contrast;

float4 PixelShader1( float2 Tex : TEXCOORD ) : COLOR0
{
float3 Color =  tex2D(baseSampler, Tex);
Color = Color - Contrast * (Color - 1.0f) * Color *(Color - 0.5f);
return float4(Color,0);
}

technique contrast
{
    pass p0
    {
        PixelShader = compile ps_2_0 PixelShader1();
    }
}

,