Skip to content

Commit c22a516

Browse files
committed
swirl persistence: make waves depend on pointer position (not movement) and keep strength nonzero; tie audio FX to energy; minor perf tweaks
1 parent 3da09f0 commit c22a516

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

crates/app-core/shaders/waves.wgsl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ fn fs_waves(inp: VsOut) -> @location(0) vec4<f32> {
105105
let depth = f32(L);
106106
let par = mix(0.65, 1.25, depth / 2.0);
107107
var cuv = cuv0 * par + vec2<f32>(0.0, -0.10 * depth);
108-
// Swirl displacement around active pointer
109-
if u.swirl_active > 0.5 {
110-
let c = (u.swirl_uv - 0.5) * vec2<f32>(aspect, 1.0) * par;
111-
let v = cuv - c;
112-
let r = length(v);
113-
let ang = u.swirl_strength * 2.5 * exp(-1.8 * r);
114-
let cs = cos(ang);
115-
let sn = sin(ang);
116-
let rot = vec2<f32>(v.x * cs - v.y * sn, v.x * sn + v.y * cs);
117-
cuv = c + rot;
118-
}
108+
// Swirl displacement driven by pointer position.
109+
// Always active; strength is provided by CPU and can be small when idle.
110+
let c = (u.swirl_uv - 0.5) * vec2<f32>(aspect, 1.0) * par;
111+
let v = cuv - c;
112+
let r = length(v);
113+
let ang = u.swirl_strength * 2.5 * exp(-1.8 * r);
114+
let cs = cos(ang);
115+
let sn = sin(ang);
116+
let rot = vec2<f32>(v.x * cs - v.y * sn, v.x * sn + v.y * cs);
117+
cuv = c + rot;
119118
// Displace coordinates by nearby voices so dragging clearly affects visuals
120119
var disp = vec2<f32>(0.0);
121120
for (var i = 0; i < 3; i = i + 1) {

crates/app-web/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,8 @@ async fn init() -> anyhow::Result<()> {
909909
let du = uv[0] - prev_uv[0];
910910
let dv = uv[1] - prev_uv[1];
911911
let speed = ((du * du + dv * dv).sqrt() / (dt_sec + 1e-5)).min(10.0);
912-
let target = ((speed * 0.25) + if ms.down { 0.6 } else { 0.0 })
913-
.clamp(0.0, 1.0);
912+
let target =
913+
((speed * 0.25) + if ms.down { 0.6 } else { 0.0 }).clamp(0.0, 1.0);
914914
swirl_energy = 0.85 * swirl_energy + 0.15 * target;
915915
prev_uv = uv;
916916
drop(ms);
@@ -932,10 +932,10 @@ async fn init() -> anyhow::Result<()> {
932932
// Direct sound↔visual link: map position to per-voice mix and fx
933933
let dist = (pos.x * pos.x + pos.z * pos.z).sqrt();
934934
// Delay send increases with |x|, reverb with radial distance
935-
let mut d_amt = (0.15 + 0.85 * pos.x.abs().min(1.0))
936-
.clamp(0.0, 1.0);
937-
let mut r_amt = (0.25 + 0.75 * (dist / 2.5).clamp(0.0, 1.0))
938-
.clamp(0.0, 1.2);
935+
let mut d_amt =
936+
(0.15 + 0.85 * pos.x.abs().min(1.0)).clamp(0.0, 1.0);
937+
let mut r_amt =
938+
(0.25 + 0.75 * (dist / 2.5).clamp(0.0, 1.0)).clamp(0.0, 1.2);
939939
// Boost sends with swirl energy for pronounced movement effect
940940
let boost = 1.0 + 0.8 * swirl_energy;
941941
d_amt = (d_amt * boost).clamp(0.0, 1.2);
@@ -1006,8 +1006,7 @@ async fn init() -> anyhow::Result<()> {
10061006
colors[i].z = (colors[i].z * 1.4).min(1.0);
10071007
}
10081008
}
1009-
let mut scales: Vec<f32> =
1010-
Vec::with_capacity(3 + ring_count * 3 + 16);
1009+
let mut scales: Vec<f32> = Vec::with_capacity(3 + ring_count * 3 + 16);
10111010
scales.push(BASE_SCALE + ps[0] * SCALE_PULSE_MULTIPLIER);
10121011
scales.push(BASE_SCALE + ps[1] * SCALE_PULSE_MULTIPLIER);
10131012
scales.push(BASE_SCALE + ps[2] * SCALE_PULSE_MULTIPLIER);
@@ -1086,8 +1085,9 @@ async fn init() -> anyhow::Result<()> {
10861085

10871086
if let Some(g) = &mut gpu {
10881087
g.set_camera(cam_eye, cam_target);
1089-
// Feed mouse-driven swirl into GPU uniforms
1090-
g.set_swirl(uv, 1.0, swirl_energy > 0.05);
1088+
// Feed mouse position persistently; movement boosts strength
1089+
let strength = 0.35 + 1.0 * swirl_energy;
1090+
g.set_swirl(uv, strength, true);
10911091
// Keep WebGPU surface sized to canvas backing size
10921092
let w = canvas_for_tick.width();
10931093
let h = canvas_for_tick.height();

0 commit comments

Comments
 (0)