Skip to main content

mittens_engine/engine/ecs/component/
blur_pass.rs

1use crate::engine::ecs::component::Component;
2
3#[derive(Debug, Clone)]
4pub struct BlurPassComponent {
5    pub enabled: bool,
6    pub radius_ndc: f32,
7    pub half_res: bool,
8}
9
10impl Default for BlurPassComponent {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl BlurPassComponent {
17    pub fn new() -> Self {
18        let cfg = crate::engine::graphics::BlurPassConfig::default();
19        Self {
20            enabled: true,
21            radius_ndc: cfg.radius_ndc,
22            half_res: cfg.half_res,
23        }
24    }
25
26    pub fn with_enabled(mut self, enabled: bool) -> Self {
27        self.enabled = enabled;
28        self
29    }
30
31    pub fn with_radius_ndc(mut self, radius_ndc: f32) -> Self {
32        if radius_ndc.is_finite() {
33            self.radius_ndc = radius_ndc.max(0.0);
34        }
35        self
36    }
37
38    pub fn with_half_res(mut self, half_res: bool) -> Self {
39        self.half_res = half_res;
40        self
41    }
42}
43
44impl Component for BlurPassComponent {
45    fn name(&self) -> &'static str {
46        "blur_pass"
47    }
48
49    fn as_any(&self) -> &dyn std::any::Any {
50        self
51    }
52
53    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
54        self
55    }
56
57    fn to_mms_ast(
58        &self,
59        _world: &crate::engine::ecs::World,
60    ) -> crate::scripting::ast::ComponentExpression {
61        use crate::engine::ecs::component::ce_helpers::*;
62        ce("BlurPass")
63            .with_call("enabled", vec![b(self.enabled)])
64            .with_call("radius_ndc", vec![num(self.radius_ndc as f64)])
65            .with_call("half_res", vec![b(self.half_res)])
66    }
67}