Getting rid of branching to check if a variable is within a range in GLSL
This could be done that way:

First condition is float val = 1.0-step(shouldY, ActualY);

Then, the condition: state &gt;= 20.0 &amp;&amp; state &lt; 40.0 can be changed to 

step(20.0, state) - step(40.0, state). This equals 0.0 if outside of range and 1.0 if inside.

Let a = step(20.0, state) - step(40.0, state)

Then we know that mix function:

genType mix(genType x,
    genType y,
    genType a);


Is $$x * (1 - a) + y * a  = val * (1 - a) + (1 - val) * a  = val - 2*a*val + a$$

So final code is:

float val = 1.0-step(shouldY, ActualY);
float a = step(20.0, state) - step(40.0, state);
return val - 2.0*a*val + a;