Skip to main content

alpha2_render/builtins/
mod.rs

1//! Built-in effects, transitions and generators as data, one module per catalog group.
2
3use alpha2_gpu::CapabilityTier;
4use alpha2_shaders::{
5    CHROMA_KEY_BODY, EFFECT_HELPERS, EXPANDED_EFFECT, FOCUS_COMBINE, GAUSSIAN_BLUR,
6    GL_TRANSITION_ENTRY, GLOW_COMBINE, GLOW_THRESHOLD, LUT_3D_BODY, SHADOW_COMBINE, SHADOW_OFFSET,
7    TRANSITION_HELPERS, UNSHARP_COMBINE,
8};
9
10use crate::{
11    EffectDef, EffectId, EffectKind, EffectResourceKind, InputSpec, ParamSpec, ParamType,
12    ParamUnit, ParamValue, Renderer, ResourceSpec, ShaderDiagnostics,
13};
14
15mod effects;
16mod generators;
17mod transitions;
18
19pub(crate) use effects::blur::{
20    directional_blur_definition, tilt_shift_definition, unsharp_mask_definition,
21};
22pub(crate) use effects::stylize::drop_shadow_definition;
23
24/// Stable identifier of the built-in chroma-key effect.
25pub const CHROMA_KEY_ID: &str = "alpha2.effect.chroma-key";
26
27/// Stable identifier of the atomic Gaussian-blur effect.
28pub const GAUSSIAN_BLUR_ID: &str = "alpha2.effect.gaussian-blur";
29
30/// Internal stable identifier of one separable Gaussian-blur pass.
31pub(crate) const GAUSSIAN_BLUR_PASS_ID: &str = "alpha2.internal.gaussian-blur-pass";
32
33/// Stable identifier of the built-in glow effect.
34pub const GLOW_ID: &str = "alpha2.effect.glow";
35
36/// Internal stable identifier of glow's threshold pass.
37pub(crate) const GLOW_THRESHOLD_ID: &str = "alpha2.internal.glow-threshold";
38
39/// Internal stable identifier of glow's two-input combining pass.
40pub(crate) const GLOW_COMBINE_ID: &str = "alpha2.internal.glow-combine";
41
42/// Stable identifier of the built-in directional (one-axis Gaussian) blur.
43pub(crate) const DIRECTIONAL_BLUR_ID: &str = "alpha2.effect.directional-blur";
44
45/// Stable identifier of the built-in unsharp mask.
46pub(crate) const UNSHARP_MASK_ID: &str = "alpha2.effect.unsharp-mask";
47
48/// Internal stable identifier of unsharp mask's two-input combining pass.
49pub(crate) const UNSHARP_COMBINE_ID: &str = "alpha2.internal.unsharp-combine";
50
51/// Stable identifier of the built-in tilt-shift.
52pub(crate) const TILT_SHIFT_ID: &str = "alpha2.effect.tilt-shift";
53
54/// Internal identifier of tilt-shift's pass mixing the source and its two blurs.
55pub(crate) const FOCUS_COMBINE_ID: &str = "alpha2.internal.focus-combine";
56
57/// Stable identifier of the built-in drop shadow.
58pub(crate) const DROP_SHADOW_ID: &str = "alpha2.effect.drop-shadow";
59
60/// Internal stable identifier of drop shadow's offset pass.
61pub(crate) const SHADOW_OFFSET_ID: &str = "alpha2.internal.shadow-offset";
62
63/// Internal stable identifier of drop shadow's two-input combining pass.
64pub(crate) const SHADOW_COMBINE_ID: &str = "alpha2.internal.shadow-combine";
65
66/// `EffectDef::license` of the effects Alpha2 itself wrote.
67pub(crate) const ALPHA2_EFFECT_LICENSE: &str = "MIT; Copyright Alpha2 contributors";
68
69/// Stable identifier of the resource-backed 3D LUT effect.
70pub const LUT_3D_ID: &str = "alpha2.effect.lut-3d";
71
72/// The gl-transitions commit the ports come from.
73pub(crate) const GL_TRANSITIONS_BASE: &str = "https://github.com/gl-transitions/gl-transitions/blob/902218a1b63773ac0d0d9f491951da3392365bfe/transitions/";
74
75/// Returns fresh definitions for every public built-in clip effect.
76#[must_use]
77pub fn builtin_effect_definitions() -> Vec<EffectDef> {
78    builtin_effect_groups()
79        .into_iter()
80        .flat_map(|(_, definitions)| definitions)
81        .collect()
82}
83
84/// The public built-in effects by catalog group, in catalog order.
85pub(crate) fn builtin_effect_groups() -> Vec<(&'static str, Vec<EffectDef>)> {
86    vec![
87        ("Color", effects::color::definitions()),
88        ("Keying", effects::keying::definitions()),
89        ("Blur & Sharpen", effects::blur::definitions()),
90        ("Stylize", effects::stylize::definitions()),
91        ("Distort", effects::distort::definitions()),
92    ]
93}
94
95/// Transitions that mix the two pictures at each pixel's own place and add nothing, for every
96/// parameter value, so a matte or mask may apply to each side. A render test checks the list.
97pub const COVERAGE_COMMUTING_TRANSITIONS: [&str; 38] = [
98    "alpha2.transition.fade",
99    "alpha2.transition.circle-open",
100    "alpha2.transition.angular",
101    "alpha2.transition.directional-wipe",
102    "alpha2.transition.radial",
103    "alpha2.transition.hsv-fade",
104    "alpha2.transition.wipe-up",
105    "alpha2.transition.wipe-down",
106    "alpha2.transition.wipe-left",
107    "alpha2.transition.wipe-right",
108    "alpha2.transition.window-blinds",
109    "alpha2.transition.window-slice",
110    "alpha2.transition.wind",
111    "alpha2.transition.pinwheel",
112    "alpha2.transition.heart",
113    "alpha2.transition.horizontal-open",
114    "alpha2.transition.horizontal-close",
115    "alpha2.transition.vertical-open",
116    "alpha2.transition.vertical-close",
117    "alpha2.transition.squares-wire",
118    "alpha2.transition.gradient-wipe",
119    "alpha2.transition.color-phase",
120    "alpha2.transition.fade-grayscale",
121    "alpha2.transition.polka-dots-curtain",
122    "alpha2.transition.block-dissolve",
123    "alpha2.transition.random-squares",
124    "alpha2.transition.perlin",
125    "alpha2.transition.overexposure",
126    "alpha2.transition.burn",
127    "alpha2.transition.crosshatch",
128    "alpha2.transition.random-noise",
129    "alpha2.transition.box",
130    "alpha2.transition.chessboard",
131    "alpha2.transition.bow-tie",
132    "alpha2.transition.bow-tie-horizontal",
133    "alpha2.transition.bow-tie-vertical",
134    "alpha2.transition.polar-function",
135    "alpha2.transition.shape-wipe",
136];
137
138/// Returns fresh, data-only definitions for all built-in transitions.
139#[must_use]
140pub fn builtin_transition_definitions() -> Vec<EffectDef> {
141    builtin_transition_groups()
142        .into_iter()
143        .flat_map(|(_, definitions)| definitions)
144        .collect()
145}
146
147/// The built-in transitions by catalog group, in catalog order.
148pub(crate) fn builtin_transition_groups() -> Vec<(&'static str, Vec<EffectDef>)> {
149    vec![
150        ("Classic", transitions::classic::definitions()),
151        ("Wipes", transitions::wipes::definitions()),
152        ("Stylized", transitions::stylized::definitions()),
153        ("Shapes", transitions::shapes::definitions()),
154        ("3D", transitions::three_d::definitions()),
155        ("Zoom & Blur", transitions::zoom_blur::definitions()),
156        ("Glitch", transitions::glitch::definitions()),
157    ]
158}
159
160/// Returns fresh, data-only definitions for all built-in generators.
161///
162/// Every generator places its pattern alike: `offset` moves it by fractions of the picture's
163/// shorter side and `rotation` turns it clockwise about its origin, the picture's centre moved
164/// by `offset`. None reads the time.
165///
166/// The noise generators draw opaque greys as sRGB-encoded values, `scale` cells across the
167/// shorter side; 360 degrees of `evolution` is one step through the noise. `fractal-noise` sums
168/// up to `complexity` layers of value noise, the last weighted by the fraction, each with cells
169/// `sub_scaling` times the size and `sub_influence` times the weight of the one before, so a
170/// smaller `sub_scaling` draws finer detail; `stretch` widens the pattern along its own axes,
171/// and `contrast` and `brightness` apply about mid grey. `cellular-noise` scatters one point
172/// per cell, up to `jitter` of the way from the cell's centre to its sides, and draws the
173/// distance to the nearest point, the difference between the two nearest (dark along the
174/// borders between cells), or one grey per point.
175///
176/// The pattern generators draw squares `size` of the shorter side each, antialiased over each
177/// pixel. `checkerboard` alternates `color_a` and `color_b`, with `color_a` below and right of
178/// the pattern's origin. `grid` draws lines `line_width` of the shorter side wide in `color`,
179/// centred on the squares' borders, over `background`.
180#[must_use]
181pub fn builtin_generator_definitions() -> Vec<EffectDef> {
182    builtin_generator_groups()
183        .into_iter()
184        .flat_map(|(_, definitions)| definitions)
185        .collect()
186}
187
188pub(crate) fn builtin_generator_groups() -> Vec<(&'static str, Vec<EffectDef>)> {
189    vec![
190        ("Noise", generators::noise_definitions()),
191        ("Patterns", generators::pattern_definitions()),
192    ]
193}
194
195/// Returns the data-only definition of the built-in chroma-key effect.
196///
197/// `key_color` is compared against straight sRGB-encoded color, as a color picker shows the
198/// screen. With `distance_mode` `rgb`, pixels within `threshold` are removed, a `softness` band
199/// is partly transparent and `spill_suppression` desaturates it; `chroma` compares only chroma,
200/// so the key survives shadows.
201#[must_use]
202pub fn chroma_key_definition() -> EffectDef {
203    EffectDef {
204        id: CHROMA_KEY_ID.into(),
205        version: 1,
206        kind: EffectKind::Effect,
207        inputs: Vec::new(),
208        params: vec![
209            color("key_color", [0.0, 1.0, 0.0, 1.0]),
210            float("threshold", 0.35, 0.0, 3.0_f32.sqrt()),
211            float("softness", 0.1, f32::EPSILON, 1.0),
212            float("spill_suppression", 0.2, 0.0, 1.0),
213            choice("distance_mode", 0, &["rgb", "chroma"]),
214        ],
215        resources: Vec::new(),
216        wgsl_body: effect_body(CHROMA_KEY_BODY),
217        tier_min: CapabilityTier::TierB,
218        license: Some(ALPHA2_EFFECT_LICENSE.into()),
219    }
220}
221
222/// Returns the data-only definition of the built-in Gaussian blur.
223///
224/// Standard deviation is half the `radius`, a fraction of the shorter side. The graph draws it
225/// as separable passes ([`crate::RenderGraph::add_effect`]); its own body is never drawn.
226#[must_use]
227pub fn gaussian_blur_definition() -> EffectDef {
228    EffectDef {
229        id: GAUSSIAN_BLUR_ID.into(),
230        version: 1,
231        kind: EffectKind::Effect,
232        inputs: Vec::new(),
233        params: vec![float_step("radius", 0.012, 0.0, 1.0, 0.001)],
234        resources: Vec::new(),
235        wgsl_body: effect_body(EXPANDED_EFFECT),
236        tier_min: CapabilityTier::TierB,
237        license: Some(ALPHA2_EFFECT_LICENSE.into()),
238    }
239}
240
241pub(crate) fn gaussian_blur_pass_definition() -> EffectDef {
242    EffectDef {
243        id: GAUSSIAN_BLUR_PASS_ID.into(),
244        version: 1,
245        kind: EffectKind::Effect,
246        inputs: Vec::new(),
247        params: vec![
248            vec2("step", [0.0, 0.0]),
249            float_step(
250                "sigma",
251                1.0,
252                0.0,
253                crate::gaussian_blur::MAX_PASS_SIGMA_TAPS,
254                0.001,
255            ),
256        ],
257        resources: Vec::new(),
258        wgsl_body: effect_body(GAUSSIAN_BLUR),
259        tier_min: CapabilityTier::TierB,
260        license: Some(ALPHA2_EFFECT_LICENSE.into()),
261    }
262}
263
264/// Returns the data-only definition of the built-in glow.
265///
266/// Straight color above `threshold` is blurred with `radius` and added back scaled by
267/// `intensity`. Drawn as internal passes; its own body is never drawn.
268#[must_use]
269pub fn glow_definition() -> EffectDef {
270    EffectDef {
271        id: GLOW_ID.into(),
272        version: 1,
273        kind: EffectKind::Effect,
274        inputs: Vec::new(),
275        params: vec![
276            float("threshold", 0.6, 0.0, 1.0),
277            float("intensity", 0.8, 0.0, 3.0),
278            float("radius", 0.012, 0.0, 0.06),
279        ],
280        resources: Vec::new(),
281        wgsl_body: effect_body(EXPANDED_EFFECT),
282        tier_min: CapabilityTier::TierB,
283        license: Some(ALPHA2_EFFECT_LICENSE.into()),
284    }
285}
286
287fn glow_threshold_definition() -> EffectDef {
288    EffectDef {
289        id: GLOW_THRESHOLD_ID.into(),
290        ..simple_effect(
291            "glow-threshold",
292            GLOW_THRESHOLD,
293            vec![float("threshold", 0.6, 0.0, 1.0)],
294        )
295    }
296}
297
298// Two inputs make it a transition to the registry; drawn at progress 0.5, which it ignores.
299fn glow_combine_definition() -> EffectDef {
300    EffectDef {
301        id: GLOW_COMBINE_ID.into(),
302        version: 1,
303        kind: EffectKind::Transition,
304        inputs: Vec::new(),
305        params: vec![float("intensity", 0.8, 0.0, 3.0)],
306        resources: Vec::new(),
307        wgsl_body: effect_body(GLOW_COMBINE),
308        tier_min: CapabilityTier::TierB,
309        license: Some(ALPHA2_EFFECT_LICENSE.into()),
310    }
311}
312
313fn unsharp_combine_definition() -> EffectDef {
314    EffectDef {
315        id: UNSHARP_COMBINE_ID.into(),
316        version: 1,
317        kind: EffectKind::Transition,
318        inputs: Vec::new(),
319        params: vec![
320            float("amount", 1.0, 0.0, 5.0),
321            float("threshold", 0.0, 0.0, 1.0),
322        ],
323        resources: Vec::new(),
324        wgsl_body: effect_body(UNSHARP_COMBINE),
325        tier_min: CapabilityTier::TierB,
326        license: Some(ALPHA2_EFFECT_LICENSE.into()),
327    }
328}
329
330fn focus_combine_definition() -> EffectDef {
331    EffectDef {
332        id: FOCUS_COMBINE_ID.into(),
333        version: 1,
334        kind: EffectKind::Effect,
335        inputs: vec![
336            InputSpec {
337                name: "soft".into(),
338            },
339            InputSpec {
340                name: "blurred".into(),
341            },
342        ],
343        params: vec![
344            float("position", 0.5, 0.0, 1.0),
345            degrees("angle", 0.0, -90.0, 90.0),
346            float("focus", 0.15, 0.0, 1.0),
347            float_step("falloff", 0.25, 0.001, 1.0, 0.005),
348        ],
349        resources: Vec::new(),
350        wgsl_body: effect_body(FOCUS_COMBINE),
351        tier_min: CapabilityTier::TierB,
352        license: Some(ALPHA2_EFFECT_LICENSE.into()),
353    }
354}
355
356fn shadow_offset_definition() -> EffectDef {
357    EffectDef {
358        id: SHADOW_OFFSET_ID.into(),
359        ..simple_effect(
360            "shadow-offset",
361            SHADOW_OFFSET,
362            vec![
363                vec2("offset", [0.0, 0.0]),
364                color("color", [0.0, 0.0, 0.0, 1.0]),
365                float("opacity", 0.6, 0.0, 1.0),
366            ],
367        )
368    }
369}
370
371fn shadow_combine_definition() -> EffectDef {
372    EffectDef {
373        id: SHADOW_COMBINE_ID.into(),
374        version: 1,
375        kind: EffectKind::Transition,
376        inputs: Vec::new(),
377        params: vec![boolean("shadow_only", false)],
378        resources: Vec::new(),
379        wgsl_body: effect_body(SHADOW_COMBINE),
380        tier_min: CapabilityTier::TierB,
381        license: Some(ALPHA2_EFFECT_LICENSE.into()),
382    }
383}
384
385/// Returns the data-only definition of the resource-backed 3D LUT effect.
386#[must_use]
387pub fn lut_3d_definition() -> EffectDef {
388    EffectDef {
389        id: LUT_3D_ID.into(),
390        version: 1,
391        kind: EffectKind::Effect,
392        inputs: Vec::new(),
393        params: vec![float("strength", 1.0, 0.0, 1.0)],
394        resources: vec![ResourceSpec {
395            name: "lut".into(),
396            kind: EffectResourceKind::Lut3d,
397        }],
398        wgsl_body: effect_body(LUT_3D_BODY),
399        tier_min: CapabilityTier::TierB,
400        license: Some(ALPHA2_EFFECT_LICENSE.into()),
401    }
402}
403
404/// The passes the engine inserts itself, hidden from the effect catalog.
405pub(crate) fn internal_effect_definitions() -> Vec<EffectDef> {
406    let mut definitions = vec![
407        gaussian_blur_pass_definition(),
408        glow_threshold_definition(),
409        glow_combine_definition(),
410        shadow_offset_definition(),
411        shadow_combine_definition(),
412        unsharp_combine_definition(),
413        focus_combine_definition(),
414        crate::masking::track_matte_definition(),
415        crate::generator::generator_definition(),
416    ];
417    definitions.extend(crate::masking::mask_combine_definitions());
418    definitions.extend(crate::masking::key_mix_definitions());
419    definitions
420}
421
422impl Renderer {
423    fn register_builtin_definition(
424        &mut self,
425        definition: EffectDef,
426    ) -> Result<EffectId, ShaderDiagnostics> {
427        let id = self.register_lazily(definition)?;
428        self.effects_mut().mark_builtin(id.clone());
429        Ok(id)
430    }
431
432    /// Registers the full built-in catalog; pipelines are made on first draw or [`Self::warmup`].
433    /// Built-ins cannot be removed through the host-effect methods.
434    ///
435    /// # Errors
436    /// Returns diagnostics from the first definition that fails.
437    pub fn register_builtins(&mut self) -> Result<Vec<EffectId>, ShaderDiagnostics> {
438        for definition in internal_effect_definitions() {
439            let internal = self.register_builtin_definition(definition)?;
440            self.effects_mut().mark_internal(internal);
441        }
442        let mut definitions = builtin_effect_definitions();
443        definitions.extend(builtin_transition_definitions());
444        definitions.extend(builtin_generator_definitions());
445        let mut ids = Vec::with_capacity(definitions.len());
446        for definition in definitions {
447            ids.push(self.register_builtin_definition(definition)?);
448        }
449        Ok(ids)
450    }
451
452    /// Registers the built-in chroma-key effect.
453    ///
454    /// # Errors
455    /// Returns schema diagnostics when registration fails.
456    pub fn register_builtin_chroma_key(&mut self) -> Result<EffectId, ShaderDiagnostics> {
457        self.register_builtin_definition(chroma_key_definition())
458    }
459
460    /// Registers the public Gaussian blur and its internal pass.
461    ///
462    /// # Errors
463    /// Returns schema diagnostics when registration fails.
464    pub fn register_builtin_gaussian_blur(&mut self) -> Result<EffectId, ShaderDiagnostics> {
465        let internal = self.register_builtin_definition(gaussian_blur_pass_definition())?;
466        self.effects_mut().mark_internal(internal);
467        self.register_builtin_definition(gaussian_blur_definition())
468    }
469
470    /// Registers the built-in 3D LUT effect.
471    ///
472    /// # Errors
473    /// Returns schema diagnostics when registration fails.
474    pub fn register_builtin_lut_3d(&mut self) -> Result<EffectId, ShaderDiagnostics> {
475        self.register_builtin_definition(lut_3d_definition())
476    }
477
478    /// Registers all built-in transition definitions.
479    ///
480    /// # Errors
481    /// Diagnostics from the first failure; earlier definitions stay registered.
482    pub fn register_builtin_transitions(&mut self) -> Result<Vec<EffectId>, ShaderDiagnostics> {
483        let definitions = builtin_transition_definitions();
484        let mut ids = Vec::with_capacity(definitions.len());
485        for definition in definitions {
486            ids.push(self.register_builtin_definition(definition)?);
487        }
488        Ok(ids)
489    }
490}
491
492pub(crate) fn effect_body(body: &str) -> String {
493    format!("{EFFECT_HELPERS}\n{body}")
494}
495
496/// A public effect Alpha2 wrote, `alpha2.effect.<name>`.
497pub(crate) fn simple_effect(name: &str, body: &str, params: Vec<ParamSpec>) -> EffectDef {
498    EffectDef {
499        id: format!("alpha2.effect.{name}"),
500        version: 1,
501        kind: EffectKind::Effect,
502        inputs: Vec::new(),
503        params,
504        resources: Vec::new(),
505        wgsl_body: effect_body(body),
506        tier_min: CapabilityTier::TierB,
507        license: Some(ALPHA2_EFFECT_LICENSE.into()),
508    }
509}
510
511/// A port of gl-transitions file `source` by `author`, `alpha2.transition.<name>`.
512pub(crate) fn transition(
513    name: &str,
514    body: &str,
515    source: &str,
516    author: &str,
517    params: Vec<ParamSpec>,
518) -> EffectDef {
519    EffectDef {
520        id: format!("alpha2.transition.{name}"),
521        version: 1,
522        kind: EffectKind::Transition,
523        inputs: Vec::new(),
524        params,
525        resources: Vec::new(),
526        wgsl_body: format!("{TRANSITION_HELPERS}\n{GL_TRANSITION_ENTRY}\n{body}"),
527        tier_min: CapabilityTier::TierB,
528        license: Some(format!(
529            "MIT; Author: {author}; Source: {GL_TRANSITIONS_BASE}{source}"
530        )),
531    }
532}
533
534/// A transition Alpha2 wrote, `alpha2.transition.<name>`; its body defines `transition` over
535/// top-left uv.
536pub(crate) fn original_transition(name: &str, body: &str, params: Vec<ParamSpec>) -> EffectDef {
537    EffectDef {
538        id: format!("alpha2.transition.{name}"),
539        version: 1,
540        kind: EffectKind::Transition,
541        inputs: Vec::new(),
542        params,
543        resources: Vec::new(),
544        wgsl_body: format!("{TRANSITION_HELPERS}\n{body}"),
545        tier_min: CapabilityTier::TierB,
546        license: Some(ALPHA2_EFFECT_LICENSE.into()),
547    }
548}
549
550pub(crate) fn float(name: &str, default: f32, min: f32, max: f32) -> ParamSpec {
551    let span = max - min;
552    let step = if span > 50.0 {
553        1.0
554    } else if span <= 0.1 {
555        0.001
556    } else {
557        0.01
558    };
559    float_step(name, default, min, max, step)
560}
561
562pub(crate) fn float_step(name: &str, default: f32, min: f32, max: f32, step: f32) -> ParamSpec {
563    ParamSpec {
564        name: name.into(),
565        param_type: ParamType::Float,
566        default: ParamValue::Float(default),
567        min: Some(min),
568        max: Some(max),
569        step: Some(step),
570        unit: ParamUnit::Normalized,
571        enum_values: Vec::new(),
572    }
573}
574
575pub(crate) fn degrees(name: &str, default: f32, min: f32, max: f32) -> ParamSpec {
576    ParamSpec {
577        unit: ParamUnit::Degrees,
578        step: Some(1.0),
579        ..float(name, default, min, max)
580    }
581}
582
583pub(crate) fn vec2(name: &str, default: [f32; 2]) -> ParamSpec {
584    ParamSpec {
585        name: name.into(),
586        param_type: ParamType::Vec2,
587        default: ParamValue::Vec2(default),
588        min: None,
589        max: None,
590        step: None,
591        unit: ParamUnit::Normalized,
592        enum_values: Vec::new(),
593    }
594}
595
596pub(crate) fn vec2_range(
597    name: &str,
598    default: [f32; 2],
599    min: f32,
600    max: f32,
601    step: f32,
602) -> ParamSpec {
603    ParamSpec {
604        min: Some(min),
605        max: Some(max),
606        step: Some(step),
607        ..vec2(name, default)
608    }
609}
610
611pub(crate) fn color(name: &str, default: [f32; 4]) -> ParamSpec {
612    ParamSpec {
613        name: name.into(),
614        param_type: ParamType::Color,
615        default: ParamValue::Color(default),
616        min: None,
617        max: None,
618        step: None,
619        unit: ParamUnit::Color,
620        enum_values: Vec::new(),
621    }
622}
623
624/// Four independent progress thresholds, one per channel, in `0..=1`.
625pub(crate) fn thresholds(name: &str, default: [f32; 4]) -> ParamSpec {
626    ParamSpec {
627        name: name.into(),
628        param_type: ParamType::Vec4,
629        default: ParamValue::Vec4(default),
630        min: Some(0.0),
631        max: Some(1.0),
632        step: Some(0.01),
633        unit: ParamUnit::Normalized,
634        enum_values: Vec::new(),
635    }
636}
637
638pub(crate) fn choice(name: &str, default: u32, values: &[&str]) -> ParamSpec {
639    ParamSpec {
640        name: name.into(),
641        param_type: ParamType::Enum,
642        default: ParamValue::Enum(default),
643        min: None,
644        max: None,
645        step: None,
646        unit: ParamUnit::Enum,
647        enum_values: values.iter().map(|value| (*value).into()).collect(),
648    }
649}
650
651pub(crate) fn boolean(name: &str, default: bool) -> ParamSpec {
652    ParamSpec {
653        name: name.into(),
654        param_type: ParamType::Bool,
655        default: ParamValue::Bool(default),
656        min: None,
657        max: None,
658        step: None,
659        unit: ParamUnit::Bool,
660        enum_values: Vec::new(),
661    }
662}