Enabling YSort on Tilemap removes shader effect

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CKO

I am using the following sprite outline shader that was provided by the community:

shader_type canvas_item;
render_mode unshaded;

uniform float width : hint_range(0.0, 16.0);
uniform vec4 outline_color : hint_color;
 
void fragment()
{
	vec2 size = vec2(width) / vec2(textureSize(TEXTURE, 0));

	vec4 sprite_color = texture(TEXTURE, UV);

	float alpha = sprite_color.a;
	alpha += texture(TEXTURE, UV + vec2(0.0, -size.y)).a;
	alpha += texture(TEXTURE, UV + vec2(size.x, -size.y)).a;
	alpha += texture(TEXTURE, UV + vec2(size.x, 0.0)).a;
	alpha += texture(TEXTURE, UV + vec2(size.x, size.y)).a;
	alpha += texture(TEXTURE, UV + vec2(0.0, size.y)).a;
	alpha += texture(TEXTURE, UV + vec2(-size.x, size.y)).a;
	alpha += texture(TEXTURE, UV + vec2(-size.x, 0.0)).a;
	alpha += texture(TEXTURE, UV + vec2(-size.x, -size.y)).a;

	vec3 final_color = mix(outline_color.rgb, sprite_color.rgb, sprite_color.a);
	COLOR = vec4(final_color, clamp(alpha, 0.0, 1.0));
}

I am using it on a tilemap. When the tilemap’s ysort property is enabled, the shader stops working.

Any ideas on how this could be fixed?