0
\$\begingroup\$

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

Example [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?

Thanks in advance.

\$\endgroup\$
3
  • \$\begingroup\$ I would think do a grayscale, if above a threshold return red and below the threshold return black? float grayscale = dot(color.rgb, float3(0.3, 0.59, 0.11)); \$\endgroup\$
    – Felsir
    Jun 17, 2016 at 20:23
  • \$\begingroup\$ @Felsir Yeah, got pretty accurate results using this, thanks for the answer! \$\endgroup\$
    – Razeal
    Jun 18, 2016 at 17:19
  • \$\begingroup\$ I'll add it as answer so you can accept it (and the question will be closed). \$\endgroup\$
    – Felsir
    Jun 18, 2016 at 19:07

1 Answer 1

0
\$\begingroup\$

To create this effect convert the pixel to greyscale:

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

Then return red above the threshold and return black below it (while preserving the alpha). See what threshold value works for you.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .