use alloc::string::String;
use scenix_core::{Color, TextureId};
use scenix_math::Vec3;
use crate::traits::{double_sided_bit, option_texture_bit};
use crate::{AlphaMode, FEATURE_ALBEDO_TEXTURE, Material, PipelineKey, ShaderKind};
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LambertMaterial {
pub name: String,
pub color: Color,
pub color_texture: Option<TextureId>,
pub emissive: Vec3,
pub alpha_mode: AlphaMode,
pub double_sided: bool,
}
impl LambertMaterial {
#[inline]
pub fn new() -> Self {
Self::default()
}
#[inline]
pub const fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
}
impl Default for LambertMaterial {
#[inline]
fn default() -> Self {
Self {
name: String::new(),
color: Color::WHITE,
color_texture: None,
emissive: Vec3::ZERO,
alpha_mode: AlphaMode::Opaque,
double_sided: false,
}
}
}
impl Material for LambertMaterial {
#[inline]
fn pipeline_key(&self) -> PipelineKey {
PipelineKey::new(
ShaderKind::Lambert,
self.alpha_mode.pipeline_alpha(),
double_sided_bit(self.double_sided)
| option_texture_bit(&self.color_texture, FEATURE_ALBEDO_TEXTURE),
)
}
#[inline]
fn is_transparent(&self) -> bool {
self.alpha_mode.is_transparent()
}
#[inline]
fn double_sided(&self) -> bool {
self.double_sided
}
#[inline]
fn alpha_cutoff(&self) -> Option<f32> {
self.alpha_mode.cutoff()
}
}