diff --git a/include/effect.h b/include/effect.h index 1b696e1..6cc1704 100644 --- a/include/effect.h +++ b/include/effect.h @@ -72,6 +72,7 @@ enum effect { EFFECT_BLUR_FADEOUT = 50, EFFECT_BLUR_CROSSFADE = 51, EFFECT_2ROT_ZOOM_BLEND_BLUR = 52, + EFFECT_VWAVE_SCROLL_CROSSFADE = 55, EFFECT_VWAVE_CROSSFADE = 60, NR_EFFECTS }; diff --git a/shaders/effects/vwave_scroll_crossfade.f.glsl b/shaders/effects/vwave_scroll_crossfade.f.glsl new file mode 100644 index 0000000..b88a229 --- /dev/null +++ b/shaders/effects/vwave_scroll_crossfade.f.glsl @@ -0,0 +1,58 @@ +/* Copyright (C) 2019 Nunuhara Cabbage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +uniform sampler2D tex; // the new scene +uniform sampler2D old; // the old scene +uniform vec2 resolution; // the screen resolution +uniform float progress; // effect progress (0..1) + +in vec2 tex_coord; +out vec4 frag_color; + +#define M_PI 3.1415926535897932384626433832795 +#define OLD_PERIOD ((2.0 * M_PI) / 360.0) +#define NEW_PERIOD ((2.0 * M_PI) / 720.0) +#define OLD_SHIFT (-M_PI) +#define NEW_SHIFT (M_PI / 2.0) + +vec3 get_pixel(vec2 old_xy, vec2 new_xy) { + // influence of old color is described by: C_old = (1-t)^2 + // influence of new color increases linearly: C_new = t + // the resulting blend is not normalized + vec3 old = texture(old, old_xy).rgb; + vec3 new = texture(tex, new_xy).rgb; + float old_weight = (1.0 - progress) * (1.0 - progress); + float new_weight = progress; + return (old * old_weight + new * new_weight); +} + +float triangle(float f) { + return 1.0 - abs(f * 2.0 - 1.0); +} + +void main() { + // old: x = amp * sin((2pi/360)*y + phase + -pi) + // new: x = amp * sin((2pi/720)*y + phase + pi/2) + vec2 p = tex_coord * resolution; + float amp = triangle(progress) * 160.0; // (0..0.5..1) -> (0..160..0); + float phase = progress * M_PI * 8.0; + float old_off_x = amp * sin(OLD_PERIOD * p.y + OLD_SHIFT + phase); + float new_off_x = amp * sin(NEW_PERIOD * p.y + NEW_SHIFT + phase); + float off_y = resolution.y * progress; + vec2 old_xy = fract(vec2(p.x + old_off_x, p.y + off_y) / resolution); + vec2 new_xy = fract(vec2(p.x - new_off_x, p.y + off_y) / resolution); + frag_color = vec4(get_pixel(old_xy, new_xy), 1.0); +} diff --git a/src/effect.c b/src/effect.c index 733e25a..dc6895a 100644 --- a/src/effect.c +++ b/src/effect.c @@ -75,6 +75,7 @@ const char *effect_names[NR_EFFECTS] = { [EFFECT_BLUR_FADEOUT] = "EFFECT_BLUR_FADEOUT", [EFFECT_BLUR_CROSSFADE] = "EFFECT_BLUR_CROSSFADE", [EFFECT_2ROT_ZOOM_BLEND_BLUR] = "EFFECT_2ROT_ZOOM_BLEND_BLUR", + [EFFECT_VWAVE_SCROLL_CROSSFADE] = "EFFECT_VWAVE_SCROLL_CROSSFADE", [EFFECT_VWAVE_CROSSFADE] = "EFFECT_VWAVE_CROSSFADE", }; @@ -156,6 +157,7 @@ static struct effect_shader turn_page_shader = EFFECT_SHADER("shaders/effects/tu static struct effect_shader sepia_noise_crossfade_shader = EFFECT_SHADER("shaders/effects/sepia_noise_crossfade.f.glsl"); static struct effect_shader blur_fadeout_shader = EFFECT_SHADER("shaders/effects/blur_fadeout.f.glsl"); static struct effect_shader blur_crossfade_shader = EFFECT_SHADER("shaders/effects/blur_crossfade.f.glsl"); +static struct effect_shader vwave_scroll_crossfade_shader = EFFECT_SHADER("shaders/effects/vwave_scroll_crossfade.f.glsl"); static struct effect_shader vwave_crossfade_shader = EFFECT_SHADER("shaders/effects/vwave_crossfade.f.glsl"); static struct effect_shader *effect_shaders[NR_EFFECTS] = { @@ -173,6 +175,7 @@ static struct effect_shader *effect_shaders[NR_EFFECTS] = { [EFFECT_SEPIA_NOISE_CROSSFADE] = &sepia_noise_crossfade_shader, [EFFECT_BLUR_FADEOUT] = &blur_fadeout_shader, [EFFECT_BLUR_CROSSFADE] = &blur_crossfade_shader, + [EFFECT_VWAVE_SCROLL_CROSSFADE] = &vwave_scroll_crossfade_shader, [EFFECT_VWAVE_CROSSFADE] = &vwave_crossfade_shader, };