I'm trying to code a "Colorizer" for my 2D platform game, so I wrote a FBO, and I applied some shaders to it.
The sprites are only made from 6 colors, so I made a Shader that gets a pixel from my FBO, replace it if the corresponding color is found, or leave it if not.
Unfortunately, this don't work as expected
In the game's level editor, I'm using some transparent sprites, which modifies the final pixel's color, which isn't detected by my Shader anymore. This leads to shitty results, see by yourself :
In these pictures, I'm trying to colorize my blue sprites in green, using this palette :
And here is the code of my shaders :
gl_TexCoord = gl_MultiTexCoord0;
gl_Position = ftransform();
uniform sampler2D fboTex;
// Couleurs d'entrée
uniform vec3 iColor1;
uniform vec3 iColor2;
uniform vec3 iColor3;
uniform vec3 iColor4;
uniform vec3 iColor5;
uniform vec3 iColor6;
// Couleurs de sortie
uniform vec3 oColor1;
uniform vec3 oColor2;
uniform vec3 oColor3;
uniform vec3 oColor4;
uniform vec3 oColor5;
uniform vec3 oColor6;
vec4 color = texture2D(fboTex, gl_TexCoord.xy);
vec3 v3color = vec3(color);
gl_FragColor = color;
if(v3color == iColor1)
gl_FragColor = vec4(oColor1, color.a);
if(v3color == iColor2)
gl_FragColor = vec4(oColor2, color.a);
if(v3color == iColor3)
gl_FragColor = vec4(oColor3, color.a);
if(v3color == iColor4)
gl_FragColor = vec4(oColor4, color.a);
if(v3color == iColor5)
gl_FragColor = vec4(oColor5, color.a);
if(v3color == iColor6)
gl_FragColor = vec4(oColor6, color.a);
So here is my question : is there any way to fix this ugly "glitch" ?
I thought of applying my shader for each sprite individually, while rendering it to the FBO, but I don't know if it's possible with GLSL 1.10 (I want to use OpenGL 2.0 methods and below only). Here comes my other question too : if I do that, will I be able to use something similar to glColor for applying transparency ?
Thanks in advance !