From 64a1a6954c170f20e7b0f48753c84beb131e4d5d Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 14 Jan 2024 19:31:03 +0100 Subject: [PATCH 1/3] Remove reallocation of notes vector --- neothesia-core/src/render/waterfall/mod.rs | 6 +++--- neothesia-core/src/render/waterfall/pipeline/mod.rs | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/neothesia-core/src/render/waterfall/mod.rs b/neothesia-core/src/render/waterfall/mod.rs index 04d4eb7d..97085784 100644 --- a/neothesia-core/src/render/waterfall/mod.rs +++ b/neothesia-core/src/render/waterfall/mod.rs @@ -55,7 +55,7 @@ impl WaterfallRenderer { ) { let range_start = layout.range.start() as usize; - let mut instances = Vec::new(); + self.notes_pipeline.clear(); let mut longer_than_range = false; for note in self.notes.iter() { @@ -78,7 +78,7 @@ impl WaterfallRenderer { 0.1 }; - instances.push(NoteInstance { + self.notes_pipeline.instances().push(NoteInstance { position: [key.x(), note.start.as_secs_f32()], size: [key.width() - 1.0, h - 0.01], // h - 0.01 to make a litle gap bettwen successive notes color: color.into_linear_rgb(), @@ -96,7 +96,7 @@ impl WaterfallRenderer { ); } - self.notes_pipeline.update_instance_buffer(queue, instances); + self.notes_pipeline.prepare(queue); } pub fn update(&mut self, queue: &wgpu::Queue, time: f32) { diff --git a/neothesia-core/src/render/waterfall/pipeline/mod.rs b/neothesia-core/src/render/waterfall/pipeline/mod.rs index e8296fc1..08bc960e 100644 --- a/neothesia-core/src/render/waterfall/pipeline/mod.rs +++ b/neothesia-core/src/render/waterfall/pipeline/mod.rs @@ -93,8 +93,15 @@ impl<'a> WaterfallPipeline { render_pass.draw_indexed(0..self.quad.indices_len, 0, 0..self.instances.len()); } - pub fn update_instance_buffer(&mut self, queue: &wgpu::Queue, instances: Vec) { - self.instances.data = instances; + pub fn clear(&mut self) { + self.instances.data.clear(); + } + + pub fn instances(&mut self) -> &mut Vec { + &mut self.instances.data + } + + pub fn prepare(&self, queue: &wgpu::Queue) { self.instances.update(queue); } From a84a3261e98fb7c637c08c3f4ad2d62a4d50ed3d Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 14 Jan 2024 20:28:48 +0100 Subject: [PATCH 2/3] Waterfall shader: Move keyboard_start_y to variable --- neothesia-core/src/render/waterfall/pipeline/shader.wgsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neothesia-core/src/render/waterfall/pipeline/shader.wgsl b/neothesia-core/src/render/waterfall/pipeline/shader.wgsl index 3d9f8974..0af6e5eb 100644 --- a/neothesia-core/src/render/waterfall/pipeline/shader.wgsl +++ b/neothesia-core/src/render/waterfall/pipeline/shader.wgsl @@ -41,7 +41,8 @@ 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 y = view_uniform.size.y - view_uniform.size.y / 5.0 - size.y / 2.0; + 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); let offset = vec2(0.0, -(note.n_position.y - time_uniform.time) * speed); From 2e26c055d842a54ed652792dab870fe7ccd3e93c Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 14 Jan 2024 20:50:12 +0100 Subject: [PATCH 3/3] 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