#[react_filter]Expand description
Turn a named-field struct into a typed custom filter for the
layer-based filter style chain.
Derives serde::Deserialize — adding #[serde(deny_unknown_fields)], so
unknown param keys reject like the built-ins; per-field #[serde(default)]
attributes you write are preserved — plus ts_rs::TS, and implements
bevy_react::filters::ReactFilter. Built-in filters stay hand-written
(they share canonical shader layouts); this macro is for custom filters,
which pack against their own shader.
Arguments:
name = "..."(optional) — the wire name; defaults to the struct ident with its first letter lowercased (Glow→"glow").shader = "path/to.wgsl"(required) — loaded withAssetServer::load, so a plain asset path relative to your assets dir;embedded://paths also work verbatim.outset = <number>(optional, default0.0) — extra logical px the effect bleeds outside the node’s rect.time = <bool>(optional, defaultfalse) — a time-driven effect re-renders its layer every frame.
The generated pack() fills the shader’s params vec4 array
contiguously in field declaration order, mapped by field type. Params
pack into at most MAX_FILTER_PARAM_VECS (8) vec4s, enforced at resolve
time — an over-cap filter is rejected at runtime with a devtools warning,
not a compile error. Shader-side, the packed array is uniforms.params
via #import bevy_react::filter (see
crates/core/src/layer/filter_prelude.wgsl for the full binding
contract).
| field type | packs as | components |
|---|---|---|
f32 | scalar | 1 |
Vec2/Vec3/Vec4 | scalars | 2/3/4 |
[f32; 2..=4] | scalars | 2–4 |
Angle | radians (a bare wire number is degrees) | 1 |
Length | logical px (px-only; other units reject the filter use via outset/resolve) | 1 |
FilterColor | linear straight-alpha RGBA | 4 |
A multi-component param that would straddle a vec4 boundary pads to the
next vec4 (the skipped components stay zero) — a ParamSlot never crosses
a vec4. Any other field type fails compilation with an error naming the
field and listing the supported types.
#[react_filter(name = "glow", shader = "shaders/glow.wgsl", outset = 4.0)]
struct GlowParams {
intensity: f32, // params[0].x
direction: Vec2, // params[0].yz
tint: FilterColor, // params[1] (padded past params[0].w)
}