]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Background/Transitions/default_transition_shader.gdshader
Squashed commit of the following:
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Background / Transitions / default_transition_shader.gdshader
1 shader_type canvas_item;
2
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;
9
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;
16
17 void fragment() {
18         vec2 frag_coord = UV;
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
23
24                 frag_coord *= ratio;
25                 frag_coord += ((vec2(1,1) - ratio) / 2.0);
26         }
27
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)));
31
32         vec4 old_frag = texture(previous_background, UV);
33         vec4 new_frag = texture(next_background, UV);
34
35         COLOR = mix(old_frag, new_frag, blend_factor);
36 }