I'm not sure right off if you can draw beyond the bounding box of the texture using a Shader. You may need to use another node and/or draw the circle using the _draw function, if you want to draw outside of the rectangle formed by the texture.
Edit: Never mind, ignore what I wrote above. I misinterpreted the question. I am leaving it above though, as you may want to use the _draw
function to draw a circle instead of doing it through a shader, depending on your use case.
I think what you'll need to do use TEXTURE_PIXEL_SIZE
to figure out the aspect ratio of the texture, and adjust. I think something like this would work but I have not tested it.
shader_type canvas_item;
uniform vec2 position;
uniform float radius;
uniform float flicker;
uniform float flicker_speed;
vec4 DrawLightSource(vec2 uv, float time, vec2 ratio_scale) {
vec2 center = position;
float flicker_radius = radius + sin(time*flicker_speed)*flicker;
if (distance(uv * ratio_scale, center) < flicker_radius) {
return vec4(0.0, 0.0, 0.0, 0);
}
return vec4(0, 0, 0, 255);
}
void fragment() {
vec2 aspect_scale = vec2(1, 1);
if (TEXTURE_PIXEL_SIZE.x != TEXTURE_PIXEL_SIZE.y) {
if (TEXTURE_PIXEL_SIZE.x < TEXTURE_PIXEL_SIZE.y) {
aspect_scale.x = TEXTURE_PIXEL_SIZE.y / TEXTURE_PIXEL_SIZE.x;
aspect_scale.y = 1.0;
} else {
aspect_scale.y = TEXTURE_PIXEL_SIZE.x / TEXTURE_PIXEL_SIZE.y;
aspect_scale.x = 1.0;
}
}
COLOR = DrawLightSource(UV, TIME, aspect_scale);
}