Attention | Topic was automatically imported from the old Question2Answer platform. | |
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.
shader_type canvas_item;
uniform vec2 offset = vec2(8,8);
uniform vec4 modulate:hint_color;
void fragment(){
vec2 ps = TEXTURE_PIXEL_SIZE;
vec4 shadow = vec4(modulate.rgb, texture(TEXTURE, UV - offset*ps).a*modulate.a);
vec4 col = texture(TEXTURE, UV);
COLOR = mix(shadow, col, col.a);
}