Skip to main content

vibe/animation/families/
optics.rs

1//! Optics & Waves Animation Family (Doppler shifts, Fresnel glows, Chromatic dispersion).
2
3use crate::animation::pga::Motor;
4use crate::animation::presets::AnimationSample;
5
6/// Evaluates the families family.
7pub fn eval(preset: &str, t: f64) -> AnimationSample {
8    match preset {
9        "doppler_shift" => {
10            let v = 0.6_f64; // 60% c
11            let doppler_factor = ((1.0_f64 + v) / (1.0_f64 - v)).sqrt();
12            let wave_phase = (t * 5.0 * doppler_factor).sin();
13            AnimationSample {
14                scalar: doppler_factor,
15                vector: [wave_phase, 0.0, 0.0],
16                motor: Motor::identity(),
17                secondary: wave_phase,
18                settled: false,
19            }
20        }
21        "fresnel_glow" | "fresnel" => {
22            let n1 = 1.0_f64;
23            let n2 = 1.5_f64;
24            let r0 = ((n1 - n2) / (n1 + n2)).powi(2);
25            let cos_theta = (t * 0.5).cos().abs();
26            let fresnel = r0 + (1.0 - r0) * (1.0 - cos_theta).powi(5);
27            AnimationSample {
28                scalar: fresnel,
29                vector: [fresnel, fresnel * 0.8, fresnel * 1.2],
30                motor: Motor::identity(),
31                secondary: cos_theta,
32                settled: false,
33            }
34        }
35        "refractive_pulse" => {
36            let n = 1.33 + (t * 4.0).sin() * 0.2;
37            AnimationSample {
38                scalar: n,
39                vector: [n, n, n],
40                motor: Motor::identity(),
41                secondary: (t * 4.0).sin(),
42                settled: false,
43            }
44        }
45        "chromatic_aberration" | "aberration" => {
46            let shift = (t * 2.0).sin() * 0.05;
47            AnimationSample {
48                scalar: shift.abs(),
49                vector: [shift, 0.0, -shift],
50                motor: Motor::identity(),
51                secondary: shift,
52                settled: false,
53            }
54        }
55        "caustic_flow" => {
56            let c1 = (t * 3.0).sin();
57            let c2 = (t * 4.5 + 1.0).sin();
58            let caustic = (c1 * c2).abs().powf(1.5);
59            AnimationSample {
60                scalar: caustic,
61                vector: [caustic, caustic, caustic * 1.3],
62                motor: Motor::identity(),
63                secondary: c1,
64                settled: false,
65            }
66        }
67        _ => AnimationSample::default(),
68    }
69}