Cut Out shader

A simple shader allowing you to cut out sprite or animated sprite to the shape you want. It takes a texture mask as parameter, and it should be the same size as the image you want to cut for best results. Transparent parts of the mask will be removed from the sprite. 

Shader code
shader_type canvas_item;

uniform sampler2D mask;

void fragment( )
{
	vec4 mask_color = texture(mask, UV).rgba;
	vec4 sprite_color = texture(TEXTURE, UV).rgba;
	
	if (mask_color.a == 0.0)
	{
		sprite_color.a = 0.0;
	}
	COLOR = sprite_color;
}
Tags
cut, mask, out, shape
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Fog of war with alpha cut off as white color

Slice and Fade out

2D shadow out of bounds

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments