pub struct Palette { /* private fields */ }Expand description
An A/B palette pair baked into two 256-entry RGB LUTs (Plan 0020 Phase 4).
A preset declares palette A ([palette]) and, optionally, palette B
([palette_b]); a bindable palette_mix (0..1) crossfades between them per
frame. With no [palette_b], lut_b == lut_a, so palette_mix is a no-op and
a single-palette preset is unchanged. Sampled on the GPU (two 256×1 textures,
lerped in-shader) and on the CPU (via sample) from the
same tables.
Clone, deliberately not Copy (Plan 0031 Phase 6): the struct is 6144
bytes ([Rgb; 256] twice), so Copy made any accidental by-value use a silent
6 KB memcpy. A scene still holds its own baked copy for deferred upload — it
just has to say .clone() to get one.
Implementations§
Source§impl Palette
impl Palette
Sourcepub fn bake(cfg: &PaletteConfig) -> Palette
pub fn bake(cfg: &PaletteConfig) -> Palette
Bake a single palette (A) into both LUTs, so palette_mix is a no-op.
Pure; off the hot path (preset load only).
Sourcepub fn bake_pair(a: &PaletteConfig, b: &PaletteConfig) -> Palette
pub fn bake_pair(a: &PaletteConfig, b: &PaletteConfig) -> Palette
Bake an A/B pair for a palette_mix crossfade. Pure; off the hot path.
Sourcepub fn default_spectrum() -> Palette
pub fn default_spectrum() -> Palette
The default palette (spectrum), used when a preset declares no
[palette] table.
Sourcepub fn sample(&self, t: f32, mix: f32) -> Rgb
pub fn sample(&self, t: f32, mix: f32) -> Rgb
Sample the crossfaded palette at t with A/B mix (0 = A, 1 = B),
linearly interpolated with the same texel-center convention (and wrap) the
GPU texture sampler uses, so the CPU (swarm) and GPU scenes color
consistently. Allocation-free — the swarm calls this per particle per
frame. mix <= 0 returns palette A exactly (matching the GPU mix at 0),
so palette_mix = 0 is identical to palette A alone.
Sourcepub fn lut_a_bytes(&self) -> [u8; 1024]
pub fn lut_a_bytes(&self) -> [u8; 1024]
Palette A’s LUT as tight RGBA8 bytes for a 256×1 Rgba8Unorm texture
upload. Alpha is opaque; the display surface is 8-bit, so 8-bit LUT storage
adds no visible banding over the analytic cosine.
Sourcepub fn lut_b_bytes(&self) -> [u8; 1024]
pub fn lut_b_bytes(&self) -> [u8; 1024]
Palette B’s LUT as tight RGBA8 bytes (the crossfade target texture).