[Shader] Pixel Smooth Filtering + Color Shift, not working as intended

Godot Version

4.3

Question

Hi, I am working on pixel art game. I applied the Smooth 3D pixel filtering to the sprite and it works fine. However, it create some wired line between different color after I add the color shift code to the shader.
Godot_v4.3-stable_win64_JZAH1wGJNb
And here is my code:

shader_type canvas_item;
render_mode unshaded;

varying flat vec4 modulate;
const vec4 self_modulate = vec4(2.0, 1.5, 1.0, 1.0);
uniform vec4[5] target_color_array : source_color;
uniform vec4[5] replace_color_array : source_color;

void vertex() {
	modulate = COLOR;
}

// Texture must have 'Filter'-flag enabled!
// Automatic smoothing
// independent of geometry and perspective
vec4 texturePointSmooth(sampler2D smp, vec2 uv, vec2 pixel_size)
{
	vec2 ddx = dFdx(uv);
	vec2 ddy = dFdy(uv);
	vec2 lxy = sqrt(ddx * ddx + ddy * ddy);
	
	vec2 uv_pixels = uv / pixel_size;
	
	vec2 uv_pixels_floor = round(uv_pixels) - vec2(0.5f);
	vec2 uv_dxy_pixels = uv_pixels - uv_pixels_floor;
	
	uv_dxy_pixels = clamp((uv_dxy_pixels - vec2(0.5f)) * pixel_size / lxy + vec2(0.5f), 0.0f, 1.0f);
	
	uv = uv_pixels_floor * pixel_size;
	
	return textureGrad(smp, uv + uv_dxy_pixels * pixel_size, ddx, ddy);
}

vec4 colorReplacer(vec4 pixelColor)
{
	for (int i=0;i<5;i++)
	{
		int j = i;
		if(pixelColor == target_color_array[j])
		{
			pixelColor = replace_color_array[j];
		}
	}
	return pixelColor;
}


void fragment()
{
	vec4 color = texturePointSmooth(TEXTURE, UV, TEXTURE_PIXEL_SIZE);
	color = colorReplacer(color);
	if ((color.r + color.g + color.b) > 1.6){
		COLOR = self_modulate * color;
		COLOR.a *= modulate.a;
	}
	else{
		COLOR = color;
	}
}

All the shader GODS, plz help a brother. :smiling_face_with_tear: