1 shader_type canvas_item;
3 // Indicates how far the transition is (0 start, 1 end).
4 uniform float progress : hint_range(0.0, 1.0);
5 // The previous background, transparent if there was none.
6 uniform sampler2D previous_background : source_color, hint_default_transparent;
7 // The next background, transparent if there is none.
8 uniform sampler2D next_background : source_color, hint_default_transparent;
10 // The texture used to determine how far along the progress has to be for bending in the new background.
11 uniform sampler2D wipe_texture : source_color;
12 // The size of the trailing smear of the transition.
13 uniform float feather : hint_range(0.0, 1.0, 0.0001) = 0.1;
14 // Determines if the wipe texture should keep it's aspect ratio when scaled to the screen's size.
15 uniform bool keep_aspect_ratio = false;
19 if(keep_aspect_ratio) {
20 vec2 ratio = (SCREEN_PIXEL_SIZE.x > SCREEN_PIXEL_SIZE.y) // determine how to scale
21 ? vec2(SCREEN_PIXEL_SIZE.y / SCREEN_PIXEL_SIZE.x, 1) // fit to width
22 : vec2(1, SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y); // fit to height
25 frag_coord += ((vec2(1,1) - ratio) / 2.0);
28 // get the blend factor between the previous and next background.
29 float alpha = (texture(wipe_texture, frag_coord).r) - progress;
30 float blend_factor = 1. - smoothstep(0., feather, alpha + (feather * (1. -progress)));
32 vec4 old_frag = texture(previous_background, UV);
33 vec4 new_frag = texture(next_background, UV);
35 COLOR = mix(old_frag, new_frag, blend_factor);