Skip to main content

scenix_material/
depth.rs

1use crate::traits::double_sided_bit;
2use crate::{AlphaMode, Material, PipelineKey, ShaderKind};
3
4/// Depth-only material used by shadow and prepass renderers.
5#[derive(Clone, Copy, Debug, PartialEq)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub struct DepthMaterial {
8    /// Alpha behavior for alpha-tested depth passes.
9    pub alpha_mode: AlphaMode,
10    /// Whether the material is rendered double-sided.
11    pub double_sided: bool,
12}
13
14impl DepthMaterial {
15    /// Creates a default opaque depth material.
16    #[inline]
17    pub const fn new() -> Self {
18        Self {
19            alpha_mode: AlphaMode::Opaque,
20            double_sided: false,
21        }
22    }
23}
24
25impl Default for DepthMaterial {
26    #[inline]
27    fn default() -> Self {
28        Self::new()
29    }
30}
31
32impl Material for DepthMaterial {
33    #[inline]
34    fn pipeline_key(&self) -> PipelineKey {
35        PipelineKey::new(
36            ShaderKind::Depth,
37            self.alpha_mode.pipeline_alpha(),
38            double_sided_bit(self.double_sided),
39        )
40    }
41
42    #[inline]
43    fn is_transparent(&self) -> bool {
44        false
45    }
46
47    #[inline]
48    fn double_sided(&self) -> bool {
49        self.double_sided
50    }
51
52    #[inline]
53    fn alpha_cutoff(&self) -> Option<f32> {
54        self.alpha_mode.cutoff()
55    }
56}