I was trying to write a shader that can change the color around a target object on the tilemap using the following code:
shader_type canvas_item;
uniform float circle_size;
uniform mat4 global_transform;
uniform vec2 target_position;
varying vec2 world_position;
void vertex() {
world_position = (global_transform * vec4(VERTEX, 1f, 0f)).xy;
}
void fragment() {
COLOR = texture(TEXTURE, UV);
float dist = distance(world_position, target_position);
COLOR.a = min(1f, dist / circle_size);
}
However the result ended up looking like this:

Also, when the target moves away from the origin(0, 0), then the circle shown above completely disappears. It looks to me like each quadrant is being rendered using the same VERTEX coordinates starting at (0, 0).
Is there some way to get the correct position of a fragment for each quadrant? Or would I have to find a workaround to achieve this effect?