//Author: peachykeen
//Title: SmartDesat
//Pack: MGE Shader Library
//Desc:
//
//     Desaturates the scene based on saturation.
//	Brighter colors get desaturated less, and the
//	overall relations are retained (if squished),
//	leaving color readable but not really there.

sampler s0;

float4 desat(in float2 Tex : TEXCOORD) : COLOR0
{
	float4 oC = tex2D(s0, Tex); // original Color
	float4 fC; // final Color
	float sat_level = normalize(oC); // saturation
	//float sat_mult = smoothstep(-1.4, 1.2, sat_level); // multiplier
	float lum = ( oC.r * 0.3 ) + ( oC.g * 0.66 ) + ( oC.b * 0.04 );
	
	fC = ( lum * ( sat_level + 0.5 ) ) + ( oC * ( 0.5 - sat_level ) );
	
	return fC;
}

Technique T0
{
	Pass p0
	{
		PixelShader = compile ps_2_0 desat();
	}
}
