# XNA HLSL Shader Color Swapping based on lightness

I'm trying to achieve a similar effect to the image below in HLSL.

[Ignore the inbetween state, currently I'm only trying to achieve the final phase, which is black and red]

What I tried so far is to sample based on which colors we perceive as brighter, ore more intense and separate the sampled colors to red and black based on that.

Code for what I've tried below:

    float4 PixelShaderFunction5(PixelShaderInput input) : COLOR0
{
float4 src = tex2D(ColorMapSampler, input.TexCoord);
float4 final = float4(0.6F,0,0,1);
float4 final2 = float4(0,0,0,1);
double a = 1 - ( 0.299 * src.r + 0.587 * src.g + 0.114 * src.b)/1;
if(src.a >0)
{
if(a>0.5)
{
return lerp(src,final,limit);
}
else return lerp(src,final2,limit);
}
else return src;
}


But this doesn't seem to result in the same effect.

Could anyone suggest me possible ways to have a similar color swapping shader?

float grayscale = dot(color.rgb, float3(0.3, 0.59, 0.11));