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§
Provided Associated Constants§
Required Methods§
Sourcefn shader(assets: &AssetServer) -> Handle<Shader>
fn shader(assets: &AssetServer) -> Handle<Shader>
The pass shader. Lazy: called inside resolve, never at registration
time, so registering filters needs no AssetServer.
Sourcefn pack(&self) -> (Vec<Vec4>, Arc<[ParamSlot]>)
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§
Sourcefn identity_params() -> Option<Value>
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.
Sourcefn outset(&self) -> Result<f32, String>
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.
Sourcefn resolve(
&self,
assets: &AssetServer,
) -> Result<Vec<ResolvedFilterPass>, String>
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".