Math toolbox
Target API: 5 · Target build:
bbb6l5(2026-11-20, production and preprod) · Status: Verified (ported to the current API — on-device re-check recommended)
// smooth quantization of 0..1 (n steps)
fn pack_bands(x: f32, n: f32) -> f32 { return floor(x * n) / n; }
// 2-level threshold (toon shadow)
let shadow = smoothstep(0.35, 0.37, level); // ±0.02 around the threshold makes steps
// 3-level toon
let b1 = smoothstep(0.20, 0.24, level);
let b2 = smoothstep(0.55, 0.59, level);
let toon = 0.45 + 0.05 * b1 + 0.5 * b2;
// luma (BT.601)
fn pack_luma(c: vec3f) -> f32 { return dot(c, vec3f(0.299, 0.587, 0.114)); }
// smooth pulse
let glow = pow(clamp(1.0 - d / radius, 0.0, 1.0), 2.0);
// triangle wave (0..1..0)
fn pack_triangle(x: f32) -> f32 { return abs(fract(x) * 2.0 - 1.0); }
// seconds → "slow phase" (for effects that ignore the 3600 s wrap)
let phase = t * 0.15;