Skip to main content

wisp/
filter.rs

1//! `Filter` trait + built-in filters.
2//!
3//! Filters operate on `RenderTexture`s. Each filter declares how many passes
4//! it needs; the orchestrator on `Renderer::apply_filter` allocates a scratch
5//! `RenderTexture` when needed and ping-pongs.
6//!
7//! Built-ins:
8//! - [`blur::BlurFilter`] — separable Gaussian (M0.16)
9//! - `drop_shadow::DropShadowFilter` — alpha extract + blur + composite (M0.17)
10//! - `motion_blur::MotionBlurFilter` — velocity-driven directional blur (M0.18)
11//! - `color_matrix::ColorMatrixFilter` — 4×5 RGBA matrix (M0.18)
12
13pub mod blur;
14pub mod color_matrix;
15pub mod drop_shadow;
16pub mod motion_blur;
17
18pub use blur::BlurFilter;
19pub use color_matrix::ColorMatrixFilter;
20pub use drop_shadow::DropShadowFilter;
21pub use motion_blur::MotionBlurFilter;
22
23use crate::application::Application;
24use crate::texture::render_texture::RenderTexture;
25
26/// Per-filter render context — provides the wgpu device / queue / encoder
27/// needed to enqueue draw work for a filter pass.
28pub struct FilterContext<'a> {
29    /// The wisp `Application` (device, queue, surface).
30    pub app: &'a Application,
31    /// Command encoder this filter pass should record into.
32    pub encoder: &'a mut wgpu::CommandEncoder,
33}
34
35/// A renderable post-process filter applied to a `RenderTexture`.
36pub trait Filter: Send + Sync {
37    /// Number of passes (`>= 1`). Multi-pass filters ping-pong between two
38    /// render targets across the orchestrator.
39    fn passes(&self) -> u32;
40
41    /// Render one pass: read from `input`, write to `output`. The orchestrator
42    /// invokes this once per pass index `[0, passes())`.
43    fn render_pass(
44        &self,
45        ctx: &mut FilterContext<'_>,
46        input: &RenderTexture,
47        output: &RenderTexture,
48        pass: u32,
49    );
50}