Skip to main content

ReactFilter

Trait ReactFilter 

Source
pub trait ReactFilter:
    Send
    + Sync
    + Sized
    + 'static {
    const NAME: &'static str;
    const USES_TIME: bool = false;

    // Required methods
    fn shader(assets: &AssetServer) -> Handle<Shader>;
    fn pack(&self) -> (Vec<Vec4>, Arc<[ParamSlot]>);

    // Provided methods
    fn identity_params() -> Option<Value> { ... }
    fn outset(&self) -> Result<f32, String> { ... }
    fn resolve(
        &self,
        assets: &AssetServer,
    ) -> Result<Vec<ResolvedFilterPass>, String> { ... }
}
Expand description

A typed, named filter: how its params deserialize (strict — built-ins use #[serde(deny_unknown_fields)]), pack into shader uniforms, and resolve into render passes.

Required Associated Constants§

Source

const NAME: &'static str

The wire name in a FilterUse (camelCase, e.g. "hueRotate").

Provided Associated Constants§

Source

const USES_TIME: bool = false

Whether the effect is time-driven (must re-render every frame even with static params). None of the built-ins are.

Required Methods§

Source

fn shader(assets: &AssetServer) -> Handle<Shader>

The pass shader. Lazy: called inside resolve, never at registration time, so registering filters needs no AssetServer.

Source

fn pack(&self) -> (Vec<Vec4>, Arc<[ParamSlot]>)

Pack the params into the uniform Vec4 array plus the layout saying where each named param landed. Length params pack their logical-px value (see ParamSlot).

Contract: this is the canonical single-invocation packing; resolve overrides may repack (e.g. blur’s per-direction params), but must agree with the layout for named slots. Every slot obeys ParamSlot’s no-straddle rule: comp + len <= 4, padding to the next Vec4 where needed. #[react_filter]-generated impls fill the array contiguously in field declaration order; the built-ins keep their hand-written canonical layouts.

Provided Methods§

Source

fn identity_params() -> Option<Value>

The params JSON of this filter’s identity invocation (no visual effect), if it has one — brightness/contrast/saturate amount: 1, grayscale/sepia/invert amount: 0 (their identity is 0, NOT the CSS shorthand default of 1), blur radius: 0, hueRotate angle: 0.

Consumed by the transition engine’s filter channel: when a chain gains/loses trailing entries, the shorter side is padded with identity passes so the change fades instead of popping (see plan_filter_ease). The identity value is resolved through the normal resolve path, so its packing, layout, and shader handles match the real filter’s for free. None (the default — #[react_filter] custom filters keep it) opts out of extension: mismatched chains involving the filter swap discretely.

Source

fn outset(&self) -> Result<f32, String>

Extra logical px the effect bleeds outside the node’s rect (blur reach). Identity for most filters. Fallible so params that cannot yield a px value (blur’s non-px radius) reject instead of silently packing 0.0.

Source

fn resolve( &self, assets: &AssetServer, ) -> Result<Vec<ResolvedFilterPass>, String>

Resolve into render passes. The default builds one pass straight from pack (see resolve_single_pass); multi-pass effects (blur: H then V) override it. Passes come back with wire_index: 0 — resolve fns don’t know their chain position; the chain resolver rewrites it (see ResolvedFilterPass::wire_index).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ReactFilter for BloomParams

Source§

const NAME: &'static str = "bloom"

Source§

impl ReactFilter for BlurParams

Source§

const NAME: &'static str = "blur"

Source§

impl ReactFilter for BrightnessParams

Source§

const NAME: &'static str = "brightness"

Source§

impl ReactFilter for ChromaticAberrationParams

Source§

const NAME: &'static str = "chromaticAberration"

Source§

impl ReactFilter for ContrastParams

Source§

const NAME: &'static str = "contrast"

Source§

impl ReactFilter for GrayscaleParams

Source§

const NAME: &'static str = "grayscale"

Source§

impl ReactFilter for HueRotateParams

Source§

const NAME: &'static str = "hueRotate"

Source§

impl ReactFilter for InvertParams

Source§

const NAME: &'static str = "invert"

Source§

impl ReactFilter for SaturateParams

Source§

const NAME: &'static str = "saturate"

Source§

impl ReactFilter for SepiaParams

Source§

const NAME: &'static str = "sepia"