From 75539d4cdc60b1f016ecffb4c90c4cd896e2914b Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Wed, 7 Jul 2021 20:14:25 -0700 Subject: [PATCH] Implement BLIND_LR effect Very frequently used across many games. --- shaders/effects/blind_lr.f.glsl | 42 +++++++++++++++++++++++++++++++++ src/effect.c | 2 ++ 2 files changed, 44 insertions(+) create mode 100644 shaders/effects/blind_lr.f.glsl diff --git a/shaders/effects/blind_lr.f.glsl b/shaders/effects/blind_lr.f.glsl new file mode 100644 index 0000000..85cf963 --- /dev/null +++ b/shaders/effects/blind_lr.f.glsl @@ -0,0 +1,42 @@ +/* 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 NR_BANDS 14 +#define BAND_WIDTH 15 +#define EFFECT_WIDTH (NR_BANDS * BAND_WIDTH) + +void main() { + // start position of effect + float lhs = ((resolution.x + EFFECT_WIDTH) * progress) - EFFECT_WIDTH; + // current pixel x-coordinate + float p = tex_coord.x * resolution.x; + // band index + float band_no = (p - lhs) / 15.0; + // offset into the band + float offset = mod(p - lhs, 15.0); + // if offset >= band_no, use new texture + float new = step(band_no, offset); + vec3 col = mix(texture(old, tex_coord).rgb, texture(tex, tex_coord).rgb, new); + frag_color = vec4(col, 1.0); +} diff --git a/src/effect.c b/src/effect.c index bfd704b..f718ac8 100644 --- a/src/effect.c +++ b/src/effect.c @@ -130,12 +130,14 @@ static void render_effect_shader(struct effect_shader *shader, Texture *old, Tex #define EFFECT_SHADER(path) { .s = { .prepare = prepare_effect_shader }, .f_path = path} static struct effect_shader crossfade_shader = EFFECT_SHADER("shaders/effects/crossfade.f.glsl"); static struct effect_shader mosaic_shader = EFFECT_SHADER("shaders/effects/mosaic.f.glsl"); +static struct effect_shader blind_lr_shader = EFFECT_SHADER("shaders/effects/blind_lr.f.glsl"); extern GLuint main_surface_fb; static struct effect_shader *effect_shaders[NR_EFFECTS] = { [EFFECT_CROSSFADE] = &crossfade_shader, [EFFECT_CROSSFADE_MOSAIC] = &mosaic_shader, + [EFFECT_BLIND_LR] = &blind_lr_shader, }; int sact_Effect(int type, possibly_unused int time, possibly_unused int key)