   Color replacement using GLSL
  I'm interested in performing per-pixel color replacement on sprite-based graphics using a fragment shader and am running in to some issues. My current shader looks like this:uniform sampler2D texture;uniform vec3 color1;uniform vec3 replace1;void main(){vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);if(pixel == vec4(color1, 1.0))pixel = vec4(replace1, 1.0);gl_FragColor = pixel;}This seems pretty straight forward: look for a specific color (color1), if you find it replace it with another color (replace1). Now the issue I have is it never seems to be able to find any of the colors I pass in to it. For example, the sprite image I'm testing only has 6 colors total, but the only color I'm able to replace is white because it's value is vec4(1.0, 1.0, 1.0, 1.0).I believe that I am not translating the RGB integer values of my colors correctly and thus the shader is unable to find them.If I wanted to find this color: (0, 112, 236) and replace it with (112, 8, 208) I believe I need to divide each of these integer values by 256 in order to get the proper range between 0 and 1. So I'm passing in values like vec4(0.0f, 0.4375f, 0.921875f, 1.0) and vec4(0.4375f, 0.03125f, 0.8125f, 1.0f) but no replacement is ever made.Is this approach no good? What can I do to make this work for me?   
  Divide by 255 instead of 256 (This maps 0..255 to 0..1) and use some tolerances when comparing floats:if(abs(a-b)<epsilon) ...   ;  You might be running into some float resolution issue, its often dangerous to compare floats to be exactly equal. I'd try to add some small epsilon around your test value and see if that helps:vec4 testcolor = vec4(color1,1.0);float eps = 0.0001f;if(all(greaterThanEqual(pixel,testcolor-eps)) && all(lessThanEqual(pixel,testcolor+eps)))pixel = vec4(replace1,1.0);;  Thanks to the both of you :) I was able to get it working using both suggestions (dividing by 255 and using an epsilon). Here the the shader source which allows me to effectively "palette swap" two colors with two other colors:uniform sampler2D texture;uniform vec3 color1;uniform vec3 replace1;uniform vec3 color2;uniform vec3 replace2;void main(){vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);vec3 eps = vec3(0.009, 0.009, 0.009);if( all( greaterThanEqual(pixel, vec4(color1 - eps, 1.0)) ) && all( lessThanEqual(pixel, vec4(color1 + eps, 1.0)) ) )pixel = vec4(replace1, 1.0);if( all( greaterThanEqual(pixel, vec4(color2 - eps, 1.0)) ) && all( lessThanEqual(pixel, vec4(color2 + eps, 1.0)) ) )pixel = vec4(replace2, 1.0);gl_FragColor = pixel;}Thanks again to the both of you!Note that I am passing in vec3 values instead of vec4, and that's because I'm using SFML2 and it doesn't have a vec4 built in to the library.   