Skip to main content

Palette

Struct Palette 

Source
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

Source

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).

Source

pub fn bake_pair(a: &PaletteConfig, b: &PaletteConfig) -> Palette

Bake an A/B pair for a palette_mix crossfade. Pure; off the hot path.

Source

pub fn default_spectrum() -> Palette

The default palette (spectrum), used when a preset declares no [palette] table.

Source

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.

Source

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.

Source

pub fn lut_b_bytes(&self) -> [u8; 1024]

Palette B’s LUT as tight RGBA8 bytes (the crossfade target texture).

Trait Implementations§

Source§

impl Clone for Palette

Source§

fn clone(&self) -> Palette

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,