From 2e26c055d842a54ed652792dab870fe7ccd3e93c Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 14 Jan 2024 20:50:12 +0100 Subject: [PATCH] Support and allow negative animation speed --- .../src/render/waterfall/pipeline/shader.wgsl | 10 ++++++++-- neothesia/src/scene/playing_scene/mod.rs | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/neothesia-core/src/render/waterfall/pipeline/shader.wgsl b/neothesia-core/src/render/waterfall/pipeline/shader.wgsl index 0af6e5eb..5867c172 100644 --- a/neothesia-core/src/render/waterfall/pipeline/shader.wgsl +++ b/neothesia-core/src/render/waterfall/pipeline/shader.wgsl @@ -39,11 +39,17 @@ struct VertexOutput { @vertex fn vs_main(vertex: Vertex, note: NoteInstance) -> VertexOutput { let speed = time_uniform.speed / view_uniform.scale; - let size = vec2(note.size.x, note.size.y * speed); + let size = vec2(note.size.x, note.size.y * abs(speed)); let keyboard_start_y = view_uniform.size.y - view_uniform.size.y / 5.0; let y = keyboard_start_y - size.y / 2.0; - let pos = vec2(note.n_position.x, y) - vec2(0.0, size.y / 2.0); + var pos = vec2(note.n_position.x, y) - vec2(0.0, size.y / 2.0); + + // If notes are falling from down to top, we need to adjust the position, + // as their start is on top of the quad rather than down + if speed < 0.0 { + pos.y += size.y; + } let offset = vec2(0.0, -(note.n_position.y - time_uniform.time) * speed); diff --git a/neothesia/src/scene/playing_scene/mod.rs b/neothesia/src/scene/playing_scene/mod.rs index 7cdf2613..a4b95682 100644 --- a/neothesia/src/scene/playing_scene/mod.rs +++ b/neothesia/src/scene/playing_scene/mod.rs @@ -262,9 +262,16 @@ fn handle_settings_input( if key == NamedKey::PageUp { target.config.animation_speed += amount; + // 0.0 is invalid speed, let's skip it and jump to positive + if target.config.animation_speed == 0.0 { + target.config.animation_speed += amount; + } } else { target.config.animation_speed -= amount; - target.config.animation_speed = target.config.animation_speed.max(100.0); + // 0.0 is invalid speed, let's skip it and jump to negative + if target.config.animation_speed == 0.0 { + target.config.animation_speed -= amount; + } } waterfall