//Author: peachykeen
//Title: SmartSat
//Pack: MGE Shader Library
//Desc:
//
//     Saturates the scene based on saturation.
//	Brighter colors get brighter, dulls duller,
//	overall relations are retained but expanded.

texture lastshader;
sampler s0 = sampler_state{ texture=<lastshader>;minfilter = linear; magfilter = linear; mipfilter = linear; addressu=clamp; addressv = clamp; } ;

float4 sat(in float2 Tex : TEXCOORD) : COLOR0
{
	float4 oC = tex2D(s0, Tex); // original Color
	float4 fC = 0; // final Color
	float4 dS = distance(oC, fC); // saturation
	float sat_level = length(dS)/1.5;
	//float sat_mult = smoothstep(-0.4, 1.8, sat_level); // multiplier
	//float lum = ( oC.r * 0.3 ) + ( oC.g * 0.66 ) + ( oC.b * 0.04 );
	
	//fC = ( lum * sat_mult ) + ( oC * ( 1 - sat_mult ) );
	fC = oC * sat_level;
	
	return fC;
}

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