T
TaleLore
Guest
I've made a palette-swap shader that works fine if I only have fully-opaque and fully-transparent pixels in my sprites, but if I have a semi-transparent part of a sprite, then that part of the sprite doesn't look palette-swapped.
Here's the code:
I've looked everywhere for a solution to fix this but I can't. I'm not even sure what the problem is. Do you have any ideas?
Here's the code:
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform sampler2D old_palette;
uniform sampler2D new_palette;
void main()
{
int num_colours = 8;
float threshold = 0.00000005;
vec4 c = texture2D(gm_BaseTexture, v_vTexcoord);
vec4 new_c = vec4(c.r, c.g, c.b, c.a);
for (int i = 0; i < num_colours; i++) {
if ( distance(c.rgb, texture2D(old_palette, vec2(float(i) / float(num_colours), 0.0)).rgb) < threshold) {
new_c.rgb = texture2D(new_palette, vec2(float(i) / float(num_colours), 0.0)).rgb;
}
}
gl_FragColor = v_vColour * new_c;
}