[HLSL CODE] Desaturate specific color channels
Posted: 23 Nov 2014, 00:46
Simple concept, use as you see fit. I didn't add GUI/DNI functionality
Defines
Funky helper function. Picked this since it's a bit better dealing with blues.
Pixel shader code part
Some people may find use for this fighting too high saturation in specific color. Would require some extra coding if also wants controls over cyan, magenta and yellows but same concept applies.
Example magenta (just out of top of my head, didn't test but should be fairly close)
float sm = saturate( desat_magenta * ( min(r,b)-2*max(r,b)-g+r+b ));
Cheers,
prod80
Defines
Code: Select all
#define desat_red 0 //Range 0-inf.
#define desat_green 0 //Range 0-inf.
#define desat_blue 0 //Range 0-inf.
Code: Select all
float WeightedLuma(float3 color)
{
return sqrt( 0.299*( color.r*color.r ) + 0.587*( color.g*color.g ) + 0.114*( color.b*color.b ));
}
Code: Select all
color.rgb = saturate( color.rgb ); //comment out if not using LDR, but this effect should run in LDR.
float gr = WeightedLuma( color.rgb );
float r = color.r;
float g = color.g;
float b = color.b;
float sr = saturate( desat_red * ( r-b-g+r ));
float sg = saturate( desat_green * ( g-r-b+g ));
float sb = saturate( desat_blue * ( b-r-g+b ));
color.rgb = lerp( color.rgb, gr, saturate( sr + sg + sb ));
Example magenta (just out of top of my head, didn't test but should be fairly close)
float sm = saturate( desat_magenta * ( min(r,b)-2*max(r,b)-g+r+b ));
Cheers,
prod80