scenix_material/
wireframe.rs1use scenix_core::Color;
2
3use crate::traits::double_sided_bit;
4use crate::{FEATURE_WIREFRAME, Material, PipelineAlphaMode, PipelineKey, ShaderKind};
5
6#[derive(Clone, Copy, Debug, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct WireframeMaterial {
10 pub color: Color,
12 pub opacity: f32,
14 pub line_width: f32,
16 pub double_sided: bool,
18}
19
20impl WireframeMaterial {
21 #[inline]
23 pub const fn new() -> Self {
24 Self {
25 color: Color::BLACK,
26 opacity: 1.0,
27 line_width: 1.0,
28 double_sided: true,
29 }
30 }
31}
32
33impl Default for WireframeMaterial {
34 #[inline]
35 fn default() -> Self {
36 Self::new()
37 }
38}
39
40impl Material for WireframeMaterial {
41 #[inline]
42 fn pipeline_key(&self) -> PipelineKey {
43 let alpha = if self.opacity < 1.0 || self.color.a < 1.0 {
44 PipelineAlphaMode::Blend
45 } else {
46 PipelineAlphaMode::Opaque
47 };
48 PipelineKey::new(
49 ShaderKind::Wireframe,
50 alpha,
51 double_sided_bit(self.double_sided) | FEATURE_WIREFRAME,
52 )
53 }
54
55 #[inline]
56 fn is_transparent(&self) -> bool {
57 self.opacity < 1.0 || self.color.a < 1.0
58 }
59
60 #[inline]
61 fn double_sided(&self) -> bool {
62 self.double_sided
63 }
64
65 #[inline]
66 fn alpha_cutoff(&self) -> Option<f32> {
67 None
68 }
69}