mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-10 08:18:14 +03:00
Improve EFFECT_VWAVE_CROSSFADE
Improve the math in this effect so that it matches Alicesoft's implementation. This is almost a pixel-perfect recreation of the effect. The only difference is that our waves are rendered with a smoother edge.
This commit is contained in:
@@ -22,8 +22,21 @@ uniform float progress; // effect progress (0..1)
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
vec3 get_pixel(vec2 xy) {
|
||||
return mix(texture(old, xy).rgb, texture(tex, xy).rgb, progress);
|
||||
#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) {
|
||||
@@ -31,9 +44,14 @@ float triangle(float f) {
|
||||
}
|
||||
|
||||
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 scale = triangle(progress) * 80.0; // (0..0.5..1) -> (0..80..0);
|
||||
float wobble = progress * 24.0;
|
||||
float offset = sin((p.y / 100.0) - wobble) * scale;
|
||||
frag_color = vec4(get_pixel(fract(vec2(p.x + offset, p.y) / resolution)), 1.0);
|
||||
float amp = triangle(progress) * 80.0; // (0..0.5..1) -> (0..80..0);
|
||||
float phase = progress * M_PI * 8.0;
|
||||
float old_off = amp * sin(OLD_PERIOD * p.y + OLD_SHIFT + phase);
|
||||
float new_off = amp * sin(NEW_PERIOD * p.y + NEW_SHIFT + phase);
|
||||
vec2 old_xy = fract(vec2(p.x + old_off, p.y) / resolution);
|
||||
vec2 new_xy = fract(vec2(p.x - new_off, p.y) / resolution);
|
||||
frag_color = vec4(get_pixel(old_xy, new_xy), 1.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user