I am trying to write a shader that checks if a sprite is all black (0,0,0,1) or all white (1,1,1,1) and change those specific pixels into other colors. The one I have written (below) is what I have. I can make it change the black pixels and white pixels accordingly but any color that is in between, such as yellow or blue, is changed to black. I want the shader to only change black or white pixels. I would appreciate it if someone can help me wrap my mind around this.
I am still new learning shaders and am trying to start small.
I am still new learning shaders and am trying to start small.
GML:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform sampler2D texture;
uniform vec4 colorMix1;
uniform vec4 colorMix2;
vec4 newColor;
vec4 convert( vec4 con)
{
vec4 ogart;
ogart.rgba = con.rgba;
if (con.rgba == vec4 (0,0,0,1))
newColor.rgba = colorMix1.rgba;
ogart.rgba = newColor.rgba;
if (con.rgba == vec4 (1,1,1,1))
newColor.rgba = colorMix2.rgba;
ogart.rgba = newColor.rgba;
return ogart.rgba;
}
void main()
{
vec4 colorPixel = texture2D( gm_BaseTexture, v_vTexcoord );
vec4 colorOut = vec4( convert ( colorPixel.rgba ));
gl_FragColor = v_vColour * colorOut;
}