Is there different between 'if' and 'ternary operator' in GLSL?
The difference is obvious. The ternary operator will return one of the two alternative values it is given; that's what it is for. An if condition that doesn't have an else block won't do anything if the condition is false.
The ternary operator version will set color to axesColor or background. But by that point in your code, you've gone past 3 other conditions that may have changed the value of color from its initial value of background. But the ternary operator doesn't care. It will overwrite whatever is in color with either axesColor or background.
What you probably wanted was color = abs(coord.y) &lt; 0.005 ? axesColor : color;, so that the value will be preserved if the condition is false.