Skip to main content

telar_renderer_core/
shadow.rs

1use crate::preprocess::{blur_padding, blur_sigma};
2
3pub struct ShadowLayout {
4    pub sigma: f32,
5    pub padding: i32,
6    pub origin_x: f32,
7    pub origin_y: f32,
8    pub texture_width_logical: u32,
9    pub texture_height_logical: u32,
10    pub texture_width: u32,
11    pub texture_height: u32,
12}
13
14impl ShadowLayout {
15    pub fn compute(
16        blur_radius: f32,
17        world_min_x: f32,
18        world_max_x: f32,
19        world_min_y: f32,
20        world_max_y: f32,
21        scale_factor: f32,
22    ) -> Self {
23        // Padding is derived from the logical sigma so the texture margin matches the pre-scale geometry; `sigma` holds the physical sigma used by the blur pass.
24        let logical_sigma = blur_sigma(blur_radius);
25        let padding = blur_padding(logical_sigma);
26        let sigma = logical_sigma * scale_factor;
27        let origin_x = world_min_x - padding as f32;
28        let origin_y = world_min_y - padding as f32;
29        let texture_width_logical =
30            ((world_max_x - world_min_x).ceil() + 2.0 * padding as f32).max(1.0) as u32;
31        let texture_height_logical =
32            ((world_max_y - world_min_y).ceil() + 2.0 * padding as f32).max(1.0) as u32;
33        let texture_width = (texture_width_logical as f32 * scale_factor).ceil() as u32;
34        let texture_height = (texture_height_logical as f32 * scale_factor).ceil() as u32;
35        Self {
36            sigma,
37            padding,
38            origin_x,
39            origin_y,
40            texture_width_logical,
41            texture_height_logical,
42            texture_width,
43            texture_height,
44        }
45    }
46}