use alpha2_gpu::CapabilityTier;
use alpha2_shaders::{
CELLULAR_NOISE, CHECKERBOARD, EFFECT_HELPERS, FRACTAL_NOISE, GENERATOR_HELPERS, GRID,
};
use super::{
ALPHA2_EFFECT_LICENSE, boolean, choice, color, degrees, float, float_step, vec2, vec2_range,
};
use crate::{EffectDef, EffectKind, ParamSpec};
fn generator(name: &str, body: &str, params: Vec<ParamSpec>) -> EffectDef {
EffectDef {
id: format!("alpha2.generator.{name}"),
version: 1,
kind: EffectKind::Generator,
inputs: Vec::new(),
params,
resources: Vec::new(),
wgsl_body: format!("{EFFECT_HELPERS}\n{GENERATOR_HELPERS}\n{body}"),
tier_min: CapabilityTier::TierB,
license: Some(ALPHA2_EFFECT_LICENSE.into()),
}
}
fn rotation() -> ParamSpec {
degrees("rotation", 0.0, -3600.0, 3600.0)
}
fn evolution() -> ParamSpec {
degrees("evolution", 0.0, -360_000.0, 360_000.0)
}
fn seed() -> ParamSpec {
float_step("seed", 0.0, 0.0, 65535.0, 1.0)
}
fn cells_across() -> ParamSpec {
float("scale", 8.0, 0.5, 256.0)
}
fn square_side() -> ParamSpec {
float_step("size", 0.125, 0.001, 1.0, 0.001)
}
pub(super) fn noise_definitions() -> Vec<EffectDef> {
vec![
generator(
"fractal-noise",
FRACTAL_NOISE,
vec![
choice("kind", 0, &["smooth", "turbulent"]),
cells_across(),
vec2_range("stretch", [1.0, 1.0], 0.05, 20.0, 0.01),
rotation(),
vec2("offset", [0.0, 0.0]),
float_step("complexity", 4.0, 1.0, 8.0, 0.1),
float("sub_influence", 0.5, 0.0, 1.0),
float("sub_scaling", 0.5, 0.25, 1.0),
evolution(),
float("contrast", 1.0, 0.0, 10.0),
float("brightness", 0.0, -1.0, 1.0),
seed(),
],
),
generator(
"cellular-noise",
CELLULAR_NOISE,
vec![
choice("kind", 0, &["distance", "edges", "cells"]),
cells_across(),
float("jitter", 1.0, 0.0, 1.0),
rotation(),
vec2("offset", [0.0, 0.0]),
evolution(),
seed(),
boolean("invert", false),
],
),
]
}
pub(super) fn pattern_definitions() -> Vec<EffectDef> {
vec![
generator(
"checkerboard",
CHECKERBOARD,
vec![
square_side(),
color("color_a", [1.0, 1.0, 1.0, 1.0]),
color("color_b", [0.0, 0.0, 0.0, 1.0]),
vec2("offset", [0.0, 0.0]),
rotation(),
],
),
generator(
"grid",
GRID,
vec![
square_side(),
float_step("line_width", 0.004, 0.0, 1.0, 0.001),
color("color", [1.0, 1.0, 1.0, 1.0]),
color("background", [0.0, 0.0, 0.0, 0.0]),
vec2("offset", [0.0, 0.0]),
rotation(),
],
),
]
}