Add a visual effect¶
Choose an existing effect with the same kind of work, then follow its path from declaration to rendered pixels. Start with Vignette, Glow, or Camera Shake.
Read the effect pipeline before changing resources. The effect reference owns coordinate, alpha, color and timing contracts.
Choose the route¶
| Kind | Core work | Renderer work |
|---|---|---|
| Ordinary image processing, like Vignette | Declaration, semantics, logical operation | CPU algorithm; WGPU shader/packing; backend registrations |
| Composite, like Glow/Bloom | Declaration and passes using existing operations | None when existing kernels suffice |
| Transform-only, like Camera Shake | Declaration, local-time evaluation and Transform hook |
No image-processing operation, kernel, shader or uniform |
| Source sampling, like Motion Tile | Pre-transform semantics and sampling parameters | Source-specific CPU/WGPU adapters |
| Prepared-resource processing, like ASCII | Resource validation and multi-stage topology | Preparation, analysis/resolve kernels and resources |
An effect can use several operations; several operations can share a kernel.
Gaussian's two directions share one kernel, and Glow reuses extraction,
Gaussian and composition. ColourTransform is internal compiled/evaluated data,
without an authored public effect.
Find the owners¶
| Work | Owning files |
|---|---|
| Declaration and semantic decisions | Core effect_definition/catalog_entries.rs and effects/<module>.rs |
| New logical operation | Core plan/effect_passes/mod.rs |
| Kernel identity and operation mapping | Render-common kernel.rs |
| CPU algorithm, support and dispatch | Render-cpu cpu/effects.rs |
| WGPU support, packing and shader | Render-wgpu wgpu/registry.rs, wgpu/parameters/effects.rs and shaders/effects/ |
| Generated Python, schema and reference | just gen-effects; Python ergonomics overrides in scripts/effects/python_metadata.py |
Crate paths above are relative to their src/ directories. Use the
full ownership map
for specialized resources. Composite and transform-only effects can reuse
renderer behavior without new kernels.
Implement in order¶
1. Declare fields and parameters¶
Edit catalog_entries.rs.
Each entry owns the Rust variant, semantic module, canonical JSON id, class,
scope, stage, temporal policy, conservative pass estimate and original-retention
policy. It also contains:
- Native
authored,compiledandevaluatedfields, including actual serde attributes. Keep their types explicit: a color string becomes bytes; a scalar property becomes a compiled property and then an evaluated number. - Scalar/plain-track field-to-target associations and their constraints.
- Ordered parameter descriptors, defaults and optional semantic hooks.
Macros derive whole enums in their existing defining modules, wire tags, kind/class/stage projections, target identities/names, typed visitors, generic track normalization/remapping, module declarations and semantic dispatch. Preserve defaults, flattening, optional/null behavior and unknown-field rejection.
Use Vignette's complete entry as the example. A scalar association is:
amount => VignetteAmount = 59: {
ScalarPropertyDefinition {
runtime_constraint: RuntimeRange { min: 0.0, max: 1.0 },
authored_validation: Range {
min: Some(0.0), max: Some(1.0),
min_exclusive: false, max_exclusive: false,
},
}
}
Declare amount: ScalarProperty in authored,
amount: CompiledScalarProperty in compiled, and its evaluated value in
evaluated. Its descriptor uses
EffectParameterDescriptor::scalar(ScalarPropertyTarget::VignetteAmount).
For a plain numeric track, declare softness: Track<f64> in both authored and
compiled fields, then add an entry under tracks, for example:
softness => VignetteSoftness = 0: {
Range {
min: Some(0.0), max: Some(2.0),
min_exclusive: true, max_exclusive: false,
}
}
Use EffectParameterDescriptor::plain_track(PlainTrackTarget::VignetteSoftness)
for its descriptor. Share a constraint definition when properties deliberately
follow the same rule.
Every authored and compiled field is checked at compile time against the association lists. A scalar or numeric track must appear exactly once, with the correct kind. Missing or repeated associations report the effect and field name; nonexistent fields, wrong types, duplicate targets and discriminants also fail compilation. These checks run during ordinary builds, without a generator. The lists derive visitors, target metadata and ordinary normalization/remapping; descriptor completeness and semantic compatibility are additionally tested.
field_types.rs
explicitly classifies supported Rust types. Qualified scalar/track paths and
aliases resolve to the same classification. New types require a deliberate
classification there; there is no blanket rule treating every Track<T> as a
numeric track. Point properties and timing retain their separate projections.
Existing target discriminants preserve observable Rust enum casts. Allocate an
unused value across the whole generated enum: RotationDegrees = 72 is a
non-effect target, so scanning catalog entries alone misses that reserved value.
Duplicate discriminants fail compilation. Kernel bits have separate numbering.
Ordinary new tracks need no traversal overrides. The ten existing palette input
fields marked #[preserve_authored_track] retain their historical transition and
normalization behavior; do not copy that marker to a new effect by default.
For typed point/timing projections, use CompiledPointProperty/ActiveInterval
or their canonical crate::plan::/crate::project:: paths, with field attributes
as needed. Aliases and other paths to these specialized point/timing types fail
compilation with use canonical point/timing type paths, so they cannot silently
bypass normalization or timing/remapping.
2. Implement semantic decisions¶
Add crates/vestra-core/src/effects/<module>.rs; the declaration includes it
automatically. Follow the closest existing module:
validateowns ordered scalar/plain/point validation, colors, integers and cross-field rules. Reusevalidation/helpers and deliberate diagnostic codes, messages and pointers.compilecompiles tracks/modifiers with their declared constraints and prepares immutable backend-neutral values.evaluateuses owner-local time, root project time, prepared signals and explicit seeds. Results must not depend on frame request order.static_identityandevaluated_identitydistinguish a removable static effect from an identity on one frame. Account for animation/modifiers.compiled_passesandevaluated_passesdescribe conservative reachable work and the actual frame's ordered operations.
Simple effects need no default forwarding functions. Add Dynamic, Modifiers,
PassCount or Requirements to hooks only when overriding the ordinary
property/catalog behavior, and implement the corresponding extra_dynamic,
extra_modifiers, pass_count or extra_requirements function. Palette Map
demonstrates time/resource/pass-count overrides. Missing declared overrides
fail compilation; omitted overrides use false/catalog defaults directly.
For animated point properties, follow Radial Blur's Dynamic and Modifiers
hooks: the ordinary dependency traversal covers scalar and plain tracks, while
point modifiers and authored point keyframes need these explicit policies.
These functions are statically dispatched; missing required functions fail compilation. Registration macros do not infer algorithms from parameter metadata.
The Assets hook calls local validate_assets; ASCII validates font references
there. Transform calls apply_transform after ordinary transform evaluation
on supported sources; Camera Shake owns its transform algorithm call. Motion
calls resolve_motion with an immutable layer/time/frame context; Motion Blur
samples displacement there. Basic colour entries implement compose_colour.
These routes need no new cases in the central frame evaluator.
Direct transform presentation currently supports Image, Shape, Text and Group;
the hook does not broaden the existing source-support policy.
3. Declare passes and resources¶
Use Original, Current, Temporary0, Temporary1 and explicit
EffectPassInputs. Map live inputs and outputs before coding. Preserve
retained originals and secondary inputs across both preparation and execution;
do not read a dead temporary or overwrite a still-live input.
Vignette emits one pass. Glow emits highlight extraction, horizontal/vertical Gaussian passes and additive composition using a retained original; a new Glow-like effect needs no artificial kernel. ASCII has analysis/resolve passes and a prepared atlas with its own lifetime and shared shader fragments.
For genuinely new work, add typed evaluated fields to EffectOperation in
plan/effect_passes/mod.rs.
Keep this IR backend-neutral. Conservative topology must include operations
reachable on any active frame, including when a sampled frame is an identity.
4. Register a kernel and CPU behavior¶
Add one row in render-common/kernel.rs:
The row derives the kernel enum, inventory, private bit and exhaustive operation mapping. Preserve existing order/bits. Append a new kernel with an unused bit below 64; bits are independent of enum discriminants. Gaussian demonstrates mapping several operations to one kernel.
In CPU effects, add the
algorithm and one cpu_effect_kernels! row binding explicit support to typed
dispatch. Reuse source/secondary/target surfaces, prepared atlases and pools.
A dedicated algorithm module additionally needs its ordinary Rust declaration.
Unsupported kernels need explicit unsupported entries and operation patterns;
missing capability/dispatch cases fail compilation. Preserve alpha, Gaussian
direction adapters, profiling and temporary liveness.
5. Implement WGPU behavior¶
An ordinary new WGPU kernel has three maintained locations:
- The WGSL algorithm under
crates/vestra-render-wgpu/src/shaders/effects/. - An explicit
effect_parameters!record and operation packing in parameters/effects.rs. - One registry.rs row declaring support, parameter type, exact shader label and ordered static source fragments.
That row derives shader projections, parameter variants/identities, typed uploads, maximum record size and ABI-test coverage. Preparation retains common kernel order. No separate shader, parameter-import or upload inventories are needed; shaders are included statically.
Record fields and packing stay explicit: public descriptors cannot specify GPU
layout or numerical conversion. effect_parameters! supplies aligned C layout
and structural assertions. Normally match Rust/WGSL field names; Zoom Blur
demonstrates explicit vector-component mapping. Every registered record receives
size/alignment, scalar-kind, named-offset, WGSL and typed-upload checks. These
do not prove algorithms or every packed value. Keep pixel tests and the runtime
kernel-mismatch guard.
Use the WGPU unsupported section when no implementation exists. A registered
implementation can also explicitly decline support. Registration, backend
policy, device features/limits and resource preparation remain separate checks.
Preserve RENDER-UNSUPPORTED-KERNEL, explicit-backend errors and Auto fallback.
6. Generate the public surface¶
The core-only exporter supplies descriptors/schema facts. Generation derives high-level classes/stubs, advanced typed handles, enums, collection helpers, imports/exports, enum associations, visual schema branches and the parameter reference. Package users run no generator.
scripts/generate-effects.py validates metadata and synchronizes output files.
scripts/effects/python_render.py owns Python classes, helpers, facades and stubs;
scripts/effects/reference_render.py owns the parameter reference.
Normal new effects default to vestra.effects.stylize with no Python metadata
entry. Optional scripts/effects/python_metadata.py overrides own module
placement, constructor ergonomics, naming and historical compatibility. Keep
special validation timing, inheritance and lowering adapters explicit. Existing
PseudoAscii and the Ascii schema/parser distinction remain compatibility cases.
Commit generated changes with the declaration. Do not hand-edit generated classes or refresh frozen expectations to hide a changed contract. When adding a public effect, update tests that deliberately pin the catalog's entry counts, while retaining existing compatibility specimens and adding tests for the new behavior.
Verify the result¶
In nix develop or the equivalent environment, run:
just effect-check
uv sync --locked --extra dev --reinstall-package vestra
just python-test
just docs-check
just check
effect-check covers generation, core/common/CPU tests and adapter-independent
WGPU contracts. Use just fmt for included semantic-source formatting. The
explicit reinstall ensures Python loads the changed Rust extension; ordinary
uv synchronization can reuse a cached build.
Run adapter checks separately:
Use GPU validation for adapter selection, evidence requirements and frame inspection. The effect test reference locates compatibility fixtures; Testing covers feature isolation, schema and packaging. Use Performance when measuring cost.
Before submitting:
- Add each public effect to the conformance table in
crates/vestra-render-common/src/kernel.rs. For a new kernel, add frozen kernel-order, shader-byte and packed-record rows; preserve existing specimens and update intentional catalog counts. - Test identity with animation/modifiers, conservative passes, original/secondary input liveness, validation and WGSL layout. Exercise alpha, masks/groups, effect chains, boundaries and repeated/out-of-order frame requests.
- Inspect actual pixels against an independent reference as well as backend parity. Record CPU, software-WGPU and named hardware results separately; unavailable checks remain unverified.
- Update the effect reference and support matrix to match demonstrated behavior, including limits. Commit generated output with its declaration.