summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/effect.cc16
-rw-r--r--src/gpu/effect.h13
-rw-r--r--src/gpu/effects/flash_effect.cc2
-rw-r--r--src/gpu/effects/post_process_helper.h13
-rw-r--r--src/gpu/gpu.cc6
-rw-r--r--src/gpu/gpu.h3
6 files changed, 32 insertions, 21 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc
index 58e011c..e0a9c24 100644
--- a/src/gpu/effect.cc
+++ b/src/gpu/effect.cc
@@ -226,7 +226,8 @@ void MainSequence::resize(int width, int height) {
}
}
-void MainSequence::render_frame(float global_time, float beat, float peak,
+void MainSequence::render_frame(float global_time, float beat_time,
+ float beat_phase, float peak,
float aspect_ratio, WGPUSurface surface) {
WGPUCommandEncoder encoder =
wgpuDeviceCreateCommandEncoder(gpu_ctx.device, nullptr);
@@ -260,11 +261,12 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
// Construct common uniforms once (reused for all effects)
CommonPostProcessUniforms base_uniforms = {
.resolution = {static_cast<float>(width_), static_cast<float>(height_)},
- ._pad = {0.0f, 0.0f},
.aspect_ratio = aspect_ratio,
.time = 0.0f, // Will be set per-effect
- .beat = beat,
+ .beat_time = beat_time,
+ .beat_phase = beat_phase,
.audio_intensity = peak,
+ ._pad = 0.0f,
};
for (const SequenceItem* item : scene_effects) {
@@ -564,7 +566,8 @@ void MainSequence::simulate_until(float target_time, float step_rate,
for (float t = 0.0f; t < target_time; t += step_rate) {
WGPUCommandEncoder encoder =
wgpuDeviceCreateCommandEncoder(gpu_ctx.device, nullptr);
- float beat = fmodf(t * bpm / 60.0f, 1.0f);
+ float absolute_beat_time = t * bpm / 60.0f;
+ float beat_phase = fmodf(absolute_beat_time, 1.0f);
std::vector<SequenceItem*> scene_effects, post_effects;
for (ActiveSequence& entry : sequences_) {
if (t >= entry.start_time) {
@@ -575,11 +578,12 @@ void MainSequence::simulate_until(float target_time, float step_rate,
for (const SequenceItem* item : scene_effects) {
CommonPostProcessUniforms test_uniforms = {
.resolution = {static_cast<float>(width_), static_cast<float>(height_)},
- ._pad = {0.0f, 0.0f},
.aspect_ratio = aspect_ratio,
.time = t - item->start_time,
- .beat = beat,
+ .beat_time = absolute_beat_time,
+ .beat_phase = beat_phase,
.audio_intensity = 0.0f,
+ ._pad = 0.0f,
};
item->effect->compute(encoder, test_uniforms);
}
diff --git a/src/gpu/effect.h b/src/gpu/effect.h
index ed90ac7..b9709a4 100644
--- a/src/gpu/effect.h
+++ b/src/gpu/effect.h
@@ -49,16 +49,19 @@ class Effect {
// Helper: get initialized CommonPostProcessUniforms based on current dimensions
// If aspect_ratio < 0, computes from width_/height_
- CommonPostProcessUniforms get_common_uniforms(float time = 0.0f, float beat = 0.0f,
+ CommonPostProcessUniforms get_common_uniforms(float time = 0.0f,
+ float beat_time = 0.0f,
+ float beat_phase = 0.0f,
float intensity = 0.0f,
float aspect_ratio = -1.0f) const {
return {
.resolution = {static_cast<float>(width_), static_cast<float>(height_)},
- ._pad = {0.0f, 0.0f},
.aspect_ratio = aspect_ratio < 0.0f ? static_cast<float>(width_) / static_cast<float>(height_) : aspect_ratio,
.time = time,
- .beat = beat,
+ .beat_time = beat_time,
+ .beat_phase = beat_phase,
.audio_intensity = intensity,
+ ._pad = 0.0f,
};
}
@@ -130,8 +133,8 @@ class MainSequence {
void init_test(const GpuContext& ctx);
void add_sequence(std::shared_ptr<Sequence> seq, float start_time,
int priority = 0);
- void render_frame(float global_time, float beat, float peak,
- float aspect_ratio, WGPUSurface surface);
+ void render_frame(float global_time, float beat_time, float beat_phase,
+ float peak, float aspect_ratio, WGPUSurface surface);
void resize(int width, int height);
void shutdown();
diff --git a/src/gpu/effects/flash_effect.cc b/src/gpu/effects/flash_effect.cc
index 4357c34..e53cbce 100644
--- a/src/gpu/effects/flash_effect.cc
+++ b/src/gpu/effects/flash_effect.cc
@@ -77,7 +77,7 @@ void FlashEffect::render(WGPURenderPassEncoder pass,
// Animate color based on time and beat
const float r = params_.color[0] * (0.5f + 0.5f * sinf(uniforms.time * 0.5f));
const float g = params_.color[1] * (0.5f + 0.5f * cosf(uniforms.time * 0.7f));
- const float b = params_.color[2] * (1.0f + 0.3f * uniforms.beat);
+ const float b = params_.color[2] * (1.0f + 0.3f * uniforms.beat_phase);
// Update uniforms with computed (animated) values
const FlashUniforms u = {
diff --git a/src/gpu/effects/post_process_helper.h b/src/gpu/effects/post_process_helper.h
index 23cde0e..1c649e7 100644
--- a/src/gpu/effects/post_process_helper.h
+++ b/src/gpu/effects/post_process_helper.h
@@ -8,12 +8,13 @@
// Uniform data common to all post-processing effects
struct CommonPostProcessUniforms {
- vec2 resolution;
- float _pad[2]; // Padding for 16-byte alignment
- float aspect_ratio;
- float time;
- float beat;
- float audio_intensity;
+ vec2 resolution; // Screen dimensions
+ float aspect_ratio; // Width/height ratio
+ float time; // Physical time in seconds (unaffected by tempo)
+ float beat_time; // Musical time in beats (absolute, tempo-scaled)
+ float beat_phase; // Fractional beat (0.0-1.0 within current beat)
+ float audio_intensity;// Audio peak for beat sync
+ float _pad; // Padding for 16-byte alignment
};
static_assert(sizeof(CommonPostProcessUniforms) == 32,
"CommonPostProcessUniforms must be 32 bytes for WGSL alignment");
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index e89a2f0..41f5bcf 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -381,8 +381,10 @@ void gpu_init(PlatformState* platform_state) {
platform_state->height);
}
-void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat) {
- g_main_sequence.render_frame(time, beat, audio_peak, aspect_ratio, g_surface);
+void gpu_draw(float audio_peak, float aspect_ratio, float time,
+ float beat_time, float beat_phase) {
+ g_main_sequence.render_frame(time, beat_time, beat_phase, audio_peak,
+ aspect_ratio, g_surface);
}
void gpu_resize(int width, int height) {
diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h
index 8c59aee..c7ee89f 100644
--- a/src/gpu/gpu.h
+++ b/src/gpu/gpu.h
@@ -42,7 +42,8 @@ struct RenderPass {
class MainSequence; // Forward declaration
void gpu_init(PlatformState* platform_state);
-void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat);
+void gpu_draw(float audio_peak, float aspect_ratio, float time,
+ float beat_time, float beat_phase);
void gpu_resize(int width, int height);
void gpu_shutdown();