Multi-Frame Wipe

Wipe an image horizontally or vertically using a custom alpha. Supports wiping sprites that have multiple frames.

Tested with Godot 4.0.3, 4.1, and 4.1.1. This is a heavily modified version of Wipe Shader (4.0.3).

Shader code
shader_type canvas_item;
// Wipe an image horizontally or vertically using a custom alpha.
// Supports wiping sprites that have multiple frames.
// Taken from https://godotshaders.com/shader/multi-frame-wipe/.

uniform float percentage: hint_range(0, 1) = 1;
uniform float hidden_alpha: hint_range(0, 1) = 0;

uniform bool flip = false;
uniform bool horizontal = false;

uniform int frames = 1;

void fragment() {
	float frame_uv_size = 1.0 / float(frames);
	float uv_position = horizontal ? UV.x : UV.y;

	// Reduce the uv_position in all frames to the same relative position in the
	// first frame. For example: with 2 frames, a uv_position of 0.75 is 0.25
	// away from the second frame's start of 0.5, so it will be reduced to 0.25.
	uv_position -= frame_uv_size * floor(uv_position / frame_uv_size);

	float frame_percentage = percentage / float(frames);
	float step_value = flip ?
			step(1.0 - frame_percentage, uv_position)
			: step(uv_position, frame_percentage);

	COLOR.a = texture(TEXTURE, UV).a * (hidden_alpha + step_value);
}
Tags
image, mask, wipe
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

Wipe Shader (4.0.3)

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments