How to make sprite fragment shader extend outside of sprite bounds

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

I am trying to make a drop shadow. I found the example scripts for 2d shaders and used the offset shadow shader as a base. I found that if my assets don’t have a transparent margin the shadow would be clipped. Below is an example, both sprites have the same shader applied. The default icon has no margin so the shadow can only be seen in the transparent corners. The character on the right shows the drop shadow correctly. If the shadow was any larger, it would start to clip. The shader code can be found at the bottom of the post.

left clipping right working

shader_type canvas_item;

uniform vec2 offset = vec2(8,8);
uniform vec4 modulate:hint_color;

void fragment(){
	vec4 shadow = vec4(modulate.rgb, texture(TEXTURE, UV - offset*ps).a*modulate.a);
	vec4 col = texture(TEXTURE, UV);
	COLOR = mix(shadow, col, col.a);
:bust_in_silhouette: Reply From: MysteryGM

Normally with a drop shadow you want it to work this way. The alternatives are:

1.) Extend the vertices past the bounds, then re-size the image into the bounds.
This solves the bounds problem, but lowers the quality of the sprite.

2.) Since you are just coloring the sprite Black, then moving it, you can just repeat this using a second sprite.

Duplicate the character sprite. Make it a child, give it a new canvas material, set visibility-> Self Modulate set this to black, move it. Done.

Now you have a second sprite acting as the shadow of the first.