Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waterfall improvements #133

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions neothesia-core/src/render/waterfall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(),
Expand All @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions neothesia-core/src/render/waterfall/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoteInstance>) {
self.instances.data = instances;
pub fn clear(&mut self) {
self.instances.data.clear();
}

pub fn instances(&mut self) -> &mut Vec<NoteInstance> {
&mut self.instances.data
}

pub fn prepare(&self, queue: &wgpu::Queue) {
self.instances.update(queue);
}

Expand Down
13 changes: 10 additions & 3 deletions neothesia-core/src/render/waterfall/pipeline/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ struct VertexOutput {
@vertex
fn vs_main(vertex: Vertex, note: NoteInstance) -> VertexOutput {
let speed = time_uniform.speed / view_uniform.scale;
let size = vec2<f32>(note.size.x, note.size.y * speed);
let size = vec2<f32>(note.size.x, note.size.y * abs(speed));

let y = view_uniform.size.y - view_uniform.size.y / 5.0 - size.y / 2.0;
let pos = vec2<f32>(note.n_position.x, y) - vec2<f32>(0.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;
var pos = vec2<f32>(note.n_position.x, y) - vec2<f32>(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<f32>(0.0, -(note.n_position.y - time_uniform.time) * speed);

Expand Down
9 changes: 8 additions & 1 deletion neothesia/src/scene/playing_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading